paxdev / SetReleaseVariable

A task to set an Azure DevOps Release Variable in a way that can be shared between pipelines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SetReleaseVariable

A task to set an Azure DevOps Release Variable in a way that can be shared between pipelines

Out of the box, Azure DevOps does not provide an easy way to shared variables between Jobs in a Release Stage, or between Stages.

Donovan Brown and Stefan Stranger have demonstrated how to use the Azure DevOps REST API to update Release Variables from a Powershell script.

What I have done is to modify their scripts slightly and export an Azure DevOps Task that you can import into your own projects to enable this functionality. By default, exporting a Task Group may result in some of the system variables that your script depends on being created as parameters of the task group.

I followed Dave Lloyd's guide to setting a visibleRule that is always false that will prevent these required parameters from being shown when you add the task to to your Pipeline. Annoyingly they are still shown in the imported Task Group, but at least we have minimised the risk of them being amended in the Pipeline itself.

To use:

  1. Go to Pipelines \ Task Groups in your project.
  2. Click on Import a Task Group then Browse to SetReleaseVariable.json and click OK.
  3. Create a Release Variable you want to amend
  4. Go to your Project's task groups and Import the Json
  5. Ensure that your organisation's Project Collection Build Service has the Pipelines\Manage Build Resources permission set to Allow
  6. Add the task to a Release Job.
  7. Set the ReleaseVariableName and ValueToSet parameters
  8. From this point on in any job or stage you can access the value of your Release Variable in the normal way.

#To-Do Astute observers will note that this assumes a happy path. Ideally the task should elegantly recover from situations where it can't find or set the variable.

About

A task to set an Azure DevOps Release Variable in a way that can be shared between pipelines

License:MIT License