VSO(TFS)-获取当前日期时间作为变量 [英] VSO(TFS) - get current date time as variable

查看:158
本文介绍了VSO(TFS)-获取当前日期时间作为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取当前日期时间并将其作为变量传递给某些部署任务?

How can I get a current date-time and pass it as a variable to some Deployment task?

推荐答案

您可以定义一个具有任何值的变量,然后将该变量修改为当前日期.详细步骤如下:

You can define a variable with any value, and then modify the variable as current date. Detail steps as below:

假设变量名是time,我们将值设置为none.如果需要将变量用于环境,则可以在环境变量中定义它.否则,您应该在变量选项卡中定义它.

Assume the variable name is time, and we set the value as none. 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.

类型:内联脚本.

内嵌脚本:

$date=$(Get-Date -Format g);
Write-Host "##vso[task.setvariable variable=time]$date"

  • 我在这里使用日期格式为MM/DD/YYYY HH:MM AM/PM.您可以使用其他日期格式.
  • 对于后续的部署任务,如果要使用当前日期时间,则可以直接使用$(time).
  • I use the date format as MM/DD/YYYY HH:MM AM/PM here. You can use other date formats.
  • For the subsequent deploy task, if you want to use current date time, you can direct use $(time).

定义变量:使用表达式设置变量在创建每天重置的计数器值的示例中,该问题的答案是金币.

Documentation for Defining Variables: Set Variables Using Expressions has a nugget of gold for the answer to this question in the example for creating a counter value that is reset daily.

a: $[counter(format('{0:yyyyMMdd}', pipeline.startTime), 100)]

此处使用的 pipeline.startTime 变量很细微,在

The pipeline.startTime variable used here is subtle and not mentioned anywhere in the Pipeline Predefined Variables documentation, even when being careful to land on the correct documentation based on the pipeline method being used. As is suggested HERE and in some of the answers on this thread, certain variables may have different values or not exist at all depending on where you are while trying to access them.

这篇关于VSO(TFS)-获取当前日期时间作为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆