Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access a task output variable in Azure Dev Ops

I am trying to use the new multistage yaml pipelines to download an artifact from a specific build. The DownloadBuildArtifacts@0 task has an output variable for BuildNumber that I would like to reference further on, but I can't figure out how to access it.

In the GUI for the task there is a box that let's you set a reference name enter image description here

But from the yaml pipeline definition I can't figure out how access this variable.

- task: DownloadBuildArtifacts@0
  inputs:
    buildType: 'specific'
    project: 'Sandbox'
    pipeline: 'bash-testing'
    buildVersionToDownload: 'latest'
    downloadType: 'single'
    artifactName: 'someArtifactName'
    referenceNames: 'blahblah'
- bash: echo $BLAHBLAH_BUILDNUMBER

Simply outputs

enter image description here

like image 209
NA Slacker Avatar asked Dec 07 '22 11:12

NA Slacker


2 Answers

You set an incorrect output variable defined.

The format of define an output variable in previous task in YAML:

echo "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the value of output variable"
name: PWS

Note: isOutput=true is the key code which announce this variable is an output variable. And also, name is equals to Reference name which displayed in Classic editor UI.

enter image description here

For how to access and use this output variable in Bash task, the format of this call script is:

echo $(name.VariableName)

So, for my sample script is:

echo $(PWS.myOutputVar)
like image 197
Mengdi Liang Avatar answered Mar 12 '23 23:03

Mengdi Liang


My yaml was incorrect and Merlin Liang's comment about name being the right syntax helped me figure it out.

The correct yaml syntax needed to reference a task output variable is.

- task: DownloadBuildArtifacts@0
  inputs:
    buildType: 'specific'
    project: 'Sandbox'
    pipeline: 'bash-testing'
    buildVersionToDownload: 'latest'
    downloadType: 'single'
    artifactName: 'some-artifact-name'
  name: 'TEST'
- bash: echo $(TEST.BuildNumber)
like image 33
NA Slacker Avatar answered Mar 12 '23 21:03

NA Slacker