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)
You could add two same tasks in the pipeline, one with the condition ((Var1==A || Var1==B || Var1==C) && (Var2==2)) and another with condition ((Var1==A) &&(Var2==1)) , this should be work. @Jayendran, Indeed, you are right!
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"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With