Posted on 5 Comments

Pass parameters from build to release pipelines on Azure devops

When you need to pass parameters between your build and release pipelines it could be a real struggle if you do not want to use variable groups. Variable groups can accomplish the requested (to pass values between build and release pipelines) but this scenario is not useful for a parametric input which is a common case when deploying a project. You can accomplish that either by using a plugin from another publisher or by following the publish artifacts procedure that I will describe.

In order to pass variables between your build and release pipelines you can create/export a file containing your variable on your build agent. This file should be exported as build artifact and then downloaded on the release pipeline.

The below build pipeline implements the functionality I described. The exported file is named projectname.txt and will be located on artifacts folder on your build agent inside folder drop. For example C:\agent\1\a\drop

- dev

  vmImage: windows-latest

  - name: powerenvironment
    displayName: Where to deploy?
    type: string


- task: PowerShell@2
    targetType: 'inline'
    script: |
      $variable = '${{parameters.powerenvironment}}'
      $variable | Out-File $(Build.ArtifactStagingDirectory)\projectname.txt
      Get-Content $(Build.ArtifactStagingDirectory)\projectname.txt

- task: PublishBuildArtifacts@1
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

When you run the pipeline you will be asked for a parameter. I gave this entry my name which will be passed on release.

My release pipeline will download the build artifacts and get the value of the file. The release pipeline includes two steps.

The first one downloads the folder drop from build artifacts. The projectname.txt is located there.

Then the powershell will print the contents of the projectname.txt

You can check the result and verify you get the parameter input value from the powershell script.

Bonus content:

You can also write your input parameter as a variable on the build agent and reference this value on a later step. This should be again a powershell step on your release pipeline.

$myVariable = "ProjectName";
$myValue = Get-Content $(System.ArtifactsDirectory)/drop/projectname.txt;

Write-Host "##vso[task.setvariable variable=ProjectName]($myValue)";

Lastly create a dump archive step to reference the input parameter from the build pipeline.

In order to test, use in the archive path the ProjectName variable.

Run the pipeline and verify that input parameter is correct (I used gerasimos).

Youtube video:

5 thoughts on “Pass parameters from build to release pipelines on Azure devops

  1. Welcome

    this is a great solution to passing variables.
    but in case you have multiple projects and Builds artifacts in the same pipline

    1. depending on your solution you could create a mapping on the text file and then handle the file on the release step. This should require more scripting on the release pipeline but it is feasible to be implemented

  2. I can’t post images here
    I will try to explain
    First, imagine we have a multi-projects with the same solution.
    for every project, we mad build a pipeline with help of a path filter.

    then we have the main branch let’s call it Development.
    now we move to the release pipeline.
    in artifacts, we add 3 artifacts and in Stages, we add 1 stage only
    why is it for?
    the aim here is for all these 3 artifacts will deploy in the same server
    now the trick here is when one artifact is triggered all the 3 artifacts will download to $(System.ArtifactsDirectory) on agent “…/r1/a/” folder
    then you will have many of “projectname.txt” file

    1. Hello Mohammad, I think I understood your solution. For that setup I would use the same mechanism but I would indicate a different artifact for each project. Lets say that you have project1 with artifact1. In the PublishBuildArtifacts task you should name your artifacts and then use the name for the release step. For example, when you publish an artifact ArtifactName: ‘artifact1’ and inside you place a file projectname.txt then you can use that in the release step with $(System.ArtifactsDirectory)/project1/projectname.txt . In that way you can have a separate text file for each artifact inside your release pipeline.

  3. What would be the solution for many build artifacts in the same release pipeline

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.