sree1611
sree1611

Reputation: 362

AzureDevops - How to execute the release pipeline agent based on the custom condition which depends on the previous agent

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.

Upvotes: 1

Views: 1572

Answers (3)

yaja6021
yaja6021

Reputation: 161

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

Upvotes: 0

Hugh Lin
Hugh Lin

Reputation: 19401

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

Upvotes: 2

sree1611
sree1611

Reputation: 362

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

Upvotes: 0

Related Questions