Search code examples
azure-devopsazure-pipelines

How to set a variable during build, check it during release (classic pipelines)


I want to set a variable during build, which I can then check during release. Below is what I have tried after doing my research.

  1. Add a variable to the build:

    enter image description here

  2. In the build pipeline, add a "Powershell Script" Task with an inline script like this:

    Write-Output "##vso[task.setvariable variable=SkipRelease;isOutput=true]true"
    
  3. In the release, add a "Powershell script" with an inline script like this:

    $skipRelease = $env:SkipRelease
    Write-Output "SkipRelease variable is: $skipRelease"
    

I have tried several variations of this, reading the SkipRelease variable:

$skipRelease = "$(Build.DefinitionName.SkipRelease)"

...

$skipRelease = $(SkipRelease)

...

$skipRelease =  $($env:SkipRelease)

None of them work, SkipRelease is either not defined or empty, depending on which method I use - determined by looking in the logs.

Can I check if the SkipRelease variable is actually by the build? How can I read it from the release?


Solution

  • Instead of pipeline variables use build tags.

    For example, add a build tag named DeployApplication to a build that should trigger a release:

    echo "##vso[build.addbuildtag]DeployApplication"
    

    Tag will be added to the build:

    Build tag

    Then in the release artifacts configure a Continuous deployment trigger based on the branches and the build tags as follows:

    Continuous deployment trigger