Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure devops pipelines conditional name

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)
like image 803
user1845593 Avatar asked Jan 16 '19 08:01

user1845593


People also ask

How do you add multiple conditions in Azure pipeline?

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!


1 Answers

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"
  }
like image 198
Shayki Abramczyk Avatar answered Sep 22 '22 20:09

Shayki Abramczyk