How can I get a current date-time and pass it as a variable to some Deployment task?
相关问题
- Docker task in Azure devops won't accept "$(pw
- Authentication Failure using Git-LFS Azure DevOps
- Getting error: File extension specified '.webt
- “No test result files matching **/*.trx were found
- Azure Graph 403 Authorization_RequestDenied using
相关文章
- Override env values defined in container spec
- Build errors of missing packages in Visual Studio
- VSTS continuous integration triggers not working
- What is a good way to deploy a Perl application?
- Deploying C++ game in Linux
- Close a work item via the commit message
- Can't get Jenkins to start using Tomcat
- Increment variable value in TFS build +1
There is now a variable specific to a release stage named "Release.Deployment.StartTime" or if you use it in powershell the environment variable is "Release_Deployment_StartTime".
It's in UTC and the format is "yyyy-MM-dd HH:mm:ssZ"
ex: "2018-11-09 21:23:27Z"
NOTE: This variable is set at the time the deployment stage is started, so if you have pre-deployment approvals the time will be set before any approvals are completed. From my testing if you have multiple stages that execute at the same time it will be the same between them, even if one stage waits for the other due to limited agent availability.
I'm using Azure DevOps online, unsure if local TFS installations will have this.
An easier way is
$(Date:MMddyy)
Some options are only available in the Build Definition options section. The date formatting is one of them. However, if you were to go into the options section, set the build number format as $(Date:yyyyMMdd-HHmmss), you could then use the $(Build.BuildNumber) variable in your tasks.
More info here - https://docs.microsoft.com/en-us/vsts/build-release/concepts/definitions/build/variables?tabs=batch
For those who use Linux on tfs:
Define variable
Make sure it has "Settable at queue time set"
Create a script in root of your repository
set-build.date.sh:
Other options are listed here.
Add shell script right after get sources
Type bash to find this task.
Done, you can use
BUILD_DATE
variable in later tasks :)You can define a variable with any value, and then modify the variable as current date. Detail steps as below:
Define a variable in release
Assume the variable name is
time
, and we set the value asnone
. If you need to use the variable for a environment, you can define it in environment variables. Else you should define it in variables Tab.Add a power shell task at the begin of deploy tasks:
Type: Inline Script.
Inline script:
Note:
MM/DD/YYYY HH:MM AM/PM
here. You can use other date formats.$(time)
.