0

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.

Edoardo
  • 13
  • 5

1 Answers1

0

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

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Thank you for you answer Jesse. These yaml would work in the BUILD Pipeline, but not in the RELEASE pipeline, since you cannot use yaml there. Is that correct? – Edoardo Sep 09 '22 at 09:20
  • You can of course use YAML for both build and releases, but you can't use YAML in the releases hub. I know all very confusing. Docs: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/stages?view=azure-devops&tabs=yaml&WT.mc_id=DOP-MVP-5001511 and an example: https://github.com/microsoft/azure-devops-extension-tasks/blob/main/azure-pipelines.yml – jessehouwing Sep 09 '22 at 09:27
  • Thank you again Jesse. I saw the PowerShell script you just added. That's how you DEFINE the variables. But then, can you please explain how I can ACCESS the variables in a Manual Intervention task? – Edoardo Sep 09 '22 at 09:32
  • Just reference it like any other variable: `$(VARIABLENAME)` – jessehouwing Sep 09 '22 at 09:43
  • Thank you Jesse. I did not understand another thing: in the PowerShell script, where do I specify the json location? In my case is the following: $(System.ArtifactsDirectory)/_user_proj/swagger_artifacts/data.json – Edoardo Sep 09 '22 at 09:47
  • Oof, I just checked, the Manual Intervention task run on an agentless phase, I haven't checked in ages whether the variables actually propagate to the agentless phase, I suspect they are scoped to the job they were registered in. In that case you'll actually need to use the REST API to edit the value of the variable on the Release level. https://learn.microsoft.com/en-us/rest/api/azure/devops/release/releases/update-release?view=azure-devops-rest-6.0&tabs=HTTP&WT.mc_id=DOP-MVP-5001511 – jessehouwing Sep 09 '22 at 09:52
  • These things are now a LOT easier in YAML multi-stage pipelines. – jessehouwing Sep 09 '22 at 10:01