8

I searched all the docs about Output Variables are for build pipeline and only told me how to set in .yaml. But how to use it in release pipeline?

Supposed I have 2 variables $abc="123" $def="456" in step Login. How to set them in below text box? and How to use them in step Deploy? enter image description here

Newton Zou
  • 558
  • 1
  • 5
  • 20
  • That is explained in the docs as well (https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=classic%2Cbatch#use-output-variables-from-tasks) . You might have missed that there is a tab "Classic" next to "Yaml" – D.J. Dec 17 '19 at 07:57
  • I read the link. But I still don't understand. The first sentence is "Some tasks define output variables". But how to define output variables in the task Login as my question described? – Newton Zou Dec 17 '19 at 08:00
  • 1
    You don't set them in the textbox. The variables can only be defined in a custom task manifest. If you use a script task you can still set an output task, but there is no way to see them in the UI. You can rely set the reference part in the UI. – jessehouwing Dec 17 '19 at 09:55

1 Answers1

12

Some tasks define output variables

For brief text, it represents the follow scripts:

echo "##vso[task.setvariable variable=abc;isOutput=true]123"

Just specify the reference name in the blank of task, and then, you can call this output variable abc by using the format: <reference name>.<variable name>.

For example, if you specify the reference name as mycustom, just call the output variable by using $(mycustom.abc).

Mengdi Liang
  • 17,577
  • 2
  • 28
  • 35
  • Is it possible to use output variables in different agent within same pipeline? – sree1611 Jan 09 '20 at 12:46
  • @sree1611, you are using pipeline with YAML or classic UI? If is YAML, yes , you can. If classic UI, I'm afraid you can not. You must add the output variable as a environment variable by using script, then other agents can able to access it. – Mengdi Liang Jan 09 '20 at 12:48
  • Hope Release pipeline doesn't support YAML. Can you provide some example how to set environment variables ? – sree1611 Jan 10 '20 at 09:11
  • Environment variables are only getting updated when the release pipeline is completed. I want to use the updated variables in the same job in a different agent. – sree1611 Jan 10 '20 at 09:59
  • 1
    @sree1611 You could look at this answer which about how to set environment variable during the pipeline execution: https://stackoverflow.com/a/59357743/11508165 Let me know is it help for you:-) – Mengdi Liang Jan 12 '20 at 10:17
  • We tried to pass an output variable from a job to an agentless job within the same stage, using classic pipelines. We tried to use the various suggestions we found here, also tried the environment variable, but we failed. So now switching to a yaml pipeline. Why is this feature not available in classic pipelines? – Carl in 't Veld Sep 10 '20 at 13:12
  • @MerlinLiang-MSFT I want that after each successful task if we can update a pipeline variable(through output variable or something like) to true and for each downstream task we can set a condition to run only if this value is true. Can you guide regarding this? – Mehul Parmar Sep 20 '20 at 18:39
  • @MehulParmar I am looking into the tickets you raised. Will provide my suggestions as the answer. Pls check them. :-) – Mengdi Liang Sep 21 '20 at 06:02