Custom TFS Enviroment Variable doesn't read $(Date)

前端 未结 3 1448
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 23:13

I want to use a custom tfs variable like this:

MergedVersion: $(BuildVersion.Major).$(BuildVersion.Minor).$(Date:yy)$(DayOfYear)$(Rev:.r)

My pro

3条回答
  •  独厮守ぢ
    2020-12-11 23:44

    Some tokens are only available in the Build number format section, such as $(Date), $(Rev:r) and $(DateOfYear) you mentioned here. See Build definition options

    As a workaround, to use $(Rev:r)you can set the build number format as $(Rev:r), then use the $(Build.BuildNumber) variable in your tasks.

    To use $(Date:yy)$(DayOfYear), you can set the variables via PowerShell task as ChamindaC mentioned above.

    1. Add a PowserShell task in you build definition
    2. Copy and paste below script and save it as *.ps1 file
    3. Check in the PS file, then run the PS file in PowerShell task

      $time=$(Get-Date -Format 'yy') # you can set the date format based on your requirement $doy = (Get-Date).DayofYear Write-Host "##vso[task.setvariable variable=Date]$time" Write-Host "##vso[task.setvariable variable=DayOfYear]$doy"

    Then you can use the variables $(Date) and $(DayOfYear) in other build tasks.

提交回复
热议问题