Answers: <p>I found another solution that works even without text files just by using the Azure REST API to get the build parameters.</p>
  <p>In my release pipeline I execute this Powershell tasks first to extract any build pipeline parameters:</p>
  <pre><code>function Get-ObjectMember {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$True, ValueFromPipeline=$True)]
        [PSCustomObject]$obj
    )
    $obj | Get-Member -MemberType NoteProperty | ForEach-Object {
        $key = $_.Name
        [PSCustomObject]@{Key = $key; Value = $obj.&quot;$key&quot;}
    }
  }
  
  $url = &quot;https://dev.azure.com/$(account)/$(project)/_apis/build/builds/$(Build.BuildId)?api-version=6.0&quot;
  $build = Invoke-RestMethod -Uri $url -Headers @{
      Authorization = &quot;Bearer $env:SYSTEM_ACCESSTOKEN&quot;
  }
  $params = $build.templateParameters
  if ($params) {
    $params | Get-ObjectMember | foreach {
      Write-Host $_.Key : $_.Value
      echo &quot;##vso[task.setvariable variable=$($_.Key);]$($_.Value)&quot;
    }
  }
  </code></pre>
  <p>My build pipeline contained the parameter: <code>RELEASE_VERSION</code> and after I executed the above code, I can use <code>$(RELEASE_VERSION)</code> in my other release tasks.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-07-14T11:23:10.273Z
Answers: That actually works perfectly, thanks a lot! Thats way more convenient than what I had before.
Answers: Dario K.
Answers: CC BY-SA 4.0
Answers: 2022-07-14T11:24:19.477Z
Answers: Worth mentioning for people with a bit less experience in this, like me, that you need to authorize your release pipeline job to have access to the System Access Token used here. Its under additional options at the bottom.
Answers: Dario K.
Answers: CC BY-SA 4.0
Answers: 2024-08-22T19:54:11.780Z
Answers: Thank you for the script. FYI the powershell variable `$url` could be simplified to:"
  
  `$url = "$(System.TeamFoundationCollectionUri)/$(Build.ProjectName)/_apis/build/builds/$(Build.BuildId)?api-version=6.0"`
  
  
  
  Read more about [System.TeamFoundationCollectionUri here](https://learn.microsoft.com/en-us/azure/devops/pipelines/release/variables?view=azure-devops&tabs=batch#view-the-current-values-of-all-variables)
Answers: Jason Harris
Answers: CC BY-SA 4.0
Answers: 2022-07-11T09:12:32.330Z
Answers: 2022-07-11T09:12:32.330Z
Answers: JBernhardt
Answers: <p>In case anyone ever finds this question: I didn't find a satisfying answer. My workaround was to write my variables to a text file in the build and then publish it, download it in the deployment and publish the values as output variables to a bash task. Looks something like this:</p>
  <pre><code>source file_containing_your_vars.txt
  echo &quot;##vso[task.setvariable variable=var1;isoutput=true]$var1&quot;
  </code></pre>
  <p>the output variables parameters of this bash would need some reference name, for example job_out and you would then be able to reference the variables from other jobs in that stage like this:</p>
  <pre><code>variables['job_out.var1']
  </code></pre>
  <p>If you are running a yaml deployment pipeline (instead of one made in the portal) you can even use job output variable between stages.</p>
  <p>For portal pipelines that want to share variables between stages this exists and seems to have helped some people but I didn't get it to work:
  <a href="https://stackoverflow.com/questions/53042605/how-to-modify-azure-devops-release-definition-variable-from-a-release-task/53060141#53060141">https://stackoverflow.com/questions/53042605/how-to-modify-azure-devops-release-definition-variable-from-a-release-task/53060141#53060141</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-11-22T16:11:06.727Z
Answers: 2020-11-22T16:11:06.727Z
Answers: Dario K.
Body: <p>I have an azure devops build pipeline that builds some docker images and a release pipeline that deploys the docker images using some artifacts I publish in the build.</p>
  <p>In the build I have some parameters that allow the user to change which docker images are built. Defined like this:</p>
  <pre><code>parameters:
    - name: docker1
      displayName: Build docker image 1?
      type: boolean
      default: true
    - name: docker2
      displayName: Build docker image 2?
      type: boolean
      default: true
  </code></pre>
  <p>I now want to make jobs in my release stages dependent on these variables as well.
  So something like this:
  <a href="https://i.sstatic.net/P4WQc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/P4WQc.png" alt="azure devops release interface" /></a></p>
  <p>Now the config in this picture doesn't work.</p>
  <p>My question is how does the syntax for this work if this is just a problem of syntax or how do I make these parameters available to the release if this is more of an issue of variable scope?</p>
  <p>What I've tried:</p>
  <ul>
  <li>Just accessing the parameters with the syntax shown above <code>eq('${{ parameters.docker1 }}', true)</code></li>
  <li>Specifying the Build like one would with predefined variables of the build scope <code>eq('${{ Build.parameters.docker1 }}', true)</code></li>
  <li>looked at variable groups vaguely based on this post <a href="https://devops.stackexchange.com/questions/10070/azure-devops-build-and-release-pipeline-artifact-name-variable">Azure DevOps Build and Release pipeline artifact name variable</a> . Variable groups seem to be immutable from the build pipeline and also shared between multiple potentially simultaneous builds so this doesn't seem to work for this usecase.</li>
  </ul>
  <p>I can image that one way to solve this would probably be to write all my parameters to a file, upload this as a pipeline artifact and then write variables from this imported artifact in the release stage. I want to avoid this if possible since it feels like a very clunky workaround.</p>
  
Tags: <azure-devops><azure-pipelines>
Title: Azure DevOps: How to pass a parameter from a build to a release?
UserDisplayName: Dario K.
ThreadText: # Azure DevOps: How to pass a parameter from a build to a release?
  
  (Asked by: username_0 on 2020-10-21)
  
  I have an azure devops build pipeline that builds some docker images and a release pipeline that deploys the docker images using some artifacts I publish in the build.
  
  In the build I have some parameters that allow the user to change which docker images are built. Defined like this:
  
  ```
  parameters:
    - name: docker1
      displayName: Build docker image 1?
      type: boolean
      default: true
    - name: docker2
      displayName: Build docker image 2?
      type: boolean
      default: true
  
  ```
  
  I now want to make jobs in my release stages dependent on these variables as well.
  So something like this:
  [![azure devops release interface](https://i.sstatic.net/P4WQc.png)](https://i.sstatic.net/P4WQc.png)
  
  Now the config in this picture doesn't work.
  
  My question is how does the syntax for this work if this is just a problem of syntax or how do I make these parameters available to the release if this is more of an issue of variable scope?
  
  What I've tried:
  
  * Just accessing the parameters with the syntax shown above `eq('${{ parameters.docker1 }}', true)`
  * Specifying the Build like one would with predefined variables of the build scope `eq('${{ Build.parameters.docker1 }}', true)`
  * looked at variable groups vaguely based on this post [Azure DevOps Build and Release pipeline artifact name variable](https://devops.stackexchange.com/questions/10070/azure-devops-build-and-release-pipeline-artifact-name-variable) . Variable groups seem to be immutable from the build pipeline and also shared between multiple potentially simultaneous builds so this doesn't seem to work for this usecase.
  
  I can image that one way to solve this would probably be to write all my parameters to a file, upload this as a pipeline artifact and then write variables from this imported artifact in the release stage. I want to avoid this if possible since it feels like a very clunky workaround.
  
  **Tags:** azure-devops, azure-pipelines
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2022-07-11. Score: 1 | Accepted answer
  
  I found another solution that works even without text files just by using the Azure REST API to get the build parameters.
  
  In my release pipeline I execute this Powershell tasks first to extract any build pipeline parameters:
  
  ```
  function Get-ObjectMember {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$True, ValueFromPipeline=$True)]
        [PSCustomObject]$obj
    )
    $obj | Get-Member -MemberType NoteProperty | ForEach-Object {
        $key = $_.Name
        [PSCustomObject]@{Key = $key; Value = $obj."$key"}
    }
  }
  
  $url = "https://dev.azure.com/$(account)/$(project)/_apis/build/builds/$(Build.BuildId)?api-version=6.0"
  $build = Invoke-RestMethod -Uri $url -Headers @{
      Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
  }
  $params = $build.templateParameters
  if ($params) {
    $params | Get-ObjectMember | foreach {
      Write-Host $_.Key : $_.Value
      echo "##vso[task.setvariable variable=$($_.Key);]$($_.Value)"
    }
  }
  
  ```
  
  My build pipeline contained the parameter: `RELEASE_VERSION` and after I executed the above code, I can use `$(RELEASE_VERSION)` in my other release tasks.
  
  > **Comments:**
  > **username_0**: That actually works perfectly, thanks a lot! Thats way more convenient than what I had before.  
  > **username_0**: Worth mentioning for people with a bit less experience in this, like me, that you need to authorize your release pipeline job to have access to the System Access Token used here. Its under additional options at the bottom.  
  > **username_2**: Thank you for the script. FYI the powershell variable `$url` could be simplified to:"  `$url = "$(System.TeamFoundationCollectionUri)/$(Build.ProjectName)/_apis/build/builds/$(Build.BuildId)?api-version=6.0"`    Read more about [System.TeamFoundationCollectionUri here](https://learn.microsoft.com/en-us/azure/devops/pipelines/release/variables?view=azure-devops&tabs=batch#view-the-current-values-of-all-variables)  
  
  ---
  
  ### Answer by username_0 on 2020-11-22. Score: 1
  
  In case anyone ever finds this question: I didn't find a satisfying answer. My workaround was to write my variables to a text file in the build and then publish it, download it in the deployment and publish the values as output variables to a bash task. Looks something like this:
  
  ```
  source file_containing_your_vars.txt
  echo "##vso[task.setvariable variable=var1;isoutput=true]$var1"
  
  ```
  
  the output variables parameters of this bash would need some reference name, for example job\_out and you would then be able to reference the variables from other jobs in that stage like this:
  
  ```
  variables['job_out.var1']
  
  ```
  
  If you are running a yaml deployment pipeline (instead of one made in the portal) you can even use job output variable between stages.
  
  For portal pipelines that want to share variables between stages this exists and seems to have helped some people but I didn't get it to work:
  <https://stackoverflow.com/questions/53042605/how-to-modify-azure-devops-release-definition-variable-from-a-release-task/53060141#53060141>
  
  
  ---
  
  