Azure Release Pipeline: How to pass a variable to Manual Intervention instructions?

560 Views Asked by At

I would like to personalize the instruction message of a Manual Intervention task in a Release Pipeline.

Right now the message is very simple, as you can see: instruction message It just says "I need your intervention!".

Now I would like to add a dynamic value to it, taken from a json, an artifact, or generated by a script (Bash, Powershell or Python, for example).

I know I can set a Pipeline Variable and then add it to the instruction message but that is useless to me, because the value I need is stored on a json artifact.

Do you have any idea on how to add a variable to the instruction message? Thank you very much.

1

There are 1 best solutions below

7
jessehouwing On

There are a couple of ways to set a Variable from a script using magic commands. A few people have also written extensions to do this:

- task: SetValueFromJSON@0
  inputs:
    variableName: 'package.version'
    jsonPathExpression: '$.version'
    jsonFile: 'package.json'

From your own bash or powershell script you can also register a variable using magic log strings:

- bash: |
    echo "##vso[task.setvariable variable=sauce;]crushed tomatoes"
  name: SetVarsBash
- pwsh: |
    Write-Host "##vso[task.setvariable variable=sauce;]crushed tomatoes"
  name: SetVarsPwsh

You can use existing script commands to read the json file and fetch the value. Here is an example of me doing something similar in GitHub Actions in a powershell script. While the syntax to register a variable is a little different, the concept of taking the variable value from somewhere and registering it as a variable is the same:

$release = (& gh release view $tag --json url) | ConvertFrom-Json
if (-not $release)
{
    $env:TAG = "m$version"
    $env:VERSION = "$version"
    
    Write-Host "##vso[task.setvariable variable=VERSION;]$version"
    Write-Host "##vso[task.setvariable variable=TAG;]m$version"
}

There are some specifics documented about naming ang encoding.

These examples are in YAML, since that's easier in StackOverflow, but you can take the script contents and use them 1-on-1 in the graphic release pipelines:

Release pipeline with powershell step that uses the above powershell snippet

Pass a variable to a script task the safe way:

enter image description here