Azure devops pipelines conditional name

陌路散爱 提交于 2020-03-01 02:11:45

问题


I am using azure-devops pipelines but I am having problems to set the name of the build.

Here is a normal build definition.

pool:
  vmImage: 'VS2017-Win2016'

name: myBuildName

steps:
- task: NuGetToolInstaller@0

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

What I would like to do is to set the name with a conditional check. If (something) then X otherwise Y

I have checked the conditional documents, but no luck.

Here is what I would like to do, but obviously does not work

# if ReleaseNumber var exists
if ($(ReleaseNumber))
  name: $(ReleaseNumber).$(Build.BuildId)
else
  name: $(date:yyyyMMdd)$(rev:.r)

回答1:


Azure DevOps YAML doesn't support conditions in the values like you tried to do.

The conditional documents you looked is for jobs/tasks execution, you can specify when the task will be executed with a custom condition.

At workaround, you can add a PowerShell task that will update the build name according to your condition.

For example, keep the $(date:yyyyMMdd)$(rev:.r) in the name and run this script during the build:

if ($env:ReleaseNumber){
  Write-Host "##vso[build.updatebuildnumber]$env:ReleaseNumber.$env:Build_BuildId"
  }
else{
  Write-Host "Release Number not exist, build name not changed"
  }


来源:https://stackoverflow.com/questions/54213174/azure-devops-pipelines-conditional-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!