1
votes

I have 2 agents in my release pipeline. 2nd agent should run only based on the output of the fist agent.

1st agent has below code

ssh task:

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

2nd agent has the below custom condition

and(succeeded(), eq(variables[isNextExecutable], 'true'))

Also, I tried to update the environment variable using API(followed How to modify Azure DevOps release definition variable from a release task?) but the variables are getting updated only release pipeline is getting completed.

My questions:

1) How to execute the agent based on the custom condition based on the first agent output?

2) Is it possible to add multiple custom condition on the task level? the task should execute if the previous task is executed successfully and based some value which set up in the previous task in the same agent.

3
Add to step setting variable its own name. Then try to use in second job $[ dependencies.PreviousJobName.outputs['StepName.MyVariable'] ] You can find it in documentation point "Set a multi-job output variable" docs.microsoft.com/en-us/azure/devops/pipelines/process/…Kontekst
@Kontekst, I can see "You cannot pass a variable from one job to another job of a build pipeline unless you use YAML". Since it is a release pipeline, I cant use YAML.sree1611

3 Answers

2
votes

How to execute the agent based on the custom condition based on the first agent output?

For this issue , if you are not using the yaml release pipeline, I am afraid this is impossible.

Note that the updated variable value is scoped to the job being executed, and does not flow across jobs or stages.

This is stated in the official document. You can try to create multi stage pipelines with YAML in Azure DevOps , so that you can use multi-job output variables to pass variable value across jobs.

As a workaround ,you can define a variable in the release definition Variable, then use REST API (Definitions - Update) to update the value of the release definition variable in the agent job 1, use the updated value of the release definition variable in the next agent job, for details,please refer to this .

Is it possible to add multiple custom condition on the task level?

For this issue, the answer is yes, you only need to use script like this ##vso[task.setvariable variable={variableName};isOutput=true]{variableValue} to output it to the following task.

enter image description here

In the following task: enter image description here

enter image description here

0
votes

After so much debugging, I fund the mistake in my PowerShell script. This may help for others.

To update the release definition after the execution of the release pipeline is completed.

https://vsrm.dev.azure.com/{org}/{project}/_apis/Release/definitions**/$(Release.ReleaseId)?api-version=5.1

To update the release definition during the execution of the release pipeline use below URL, but these changes are not available in the same agent. you have to create a separate agent if you want to use modified values.

 https://vsrm.dev.azure.com/{org}/{project}/_apis/release/releases/$(Release.ReleaseId)?api-version=5.1
0
votes

If you want to use a variable within a task group, you can set isOutput=false and refer using the expression $(variable name)

https://github.com/MicrosoftDocs/azure-devops-docs/issues/6983