问题
I have 3 Jobs in Azure Devops Release Pipeline :
- Agent job1
- Agent job2
- Agent job3
I want to configure Agent job2 In such a way that it should run even if Agent job1 Fails.
for that, I have set Agent job2 property of Run this job to even if the previous job fails.
Now, I want to configure Agent job3 in such a way that it should run only if Agent job2 succeded
What configuration I need to make in Agent Job3 to make it Dependant on Agent Job2
回答1:
How Restrict the Agent Job to Run only if Specific Job succeeded
I am afraid there is no such out of box custom conditions to restrict the Agent Job to Run only if Specific Job succeeded.
As workaround, we could set a variable like RunAgentJob3 to False in the Variables:
Then, add a inline powershell task at the end of your second agent job with condition Only when all previous tasks have succeeded, just after the copy task to invoke REST API to update the variable like RunAgentJob3 to true:
$url = "https://dev.azure.com/<OrganizationName>/<ProjectName>/_apis/build/definitions/55?api-version=5.0"
Write-Host "URL: $url"
$pipeline = Invoke-RestMethod -Uri $url -Headers @{
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
}
Write-Host "Pipeline = $($pipeline | ConvertTo-Json -Depth 100)"
# Update an existing variable named RunAgentJob3to its new value true
$pipeline.variables.RunAgentJob3.value = "true"
####****************** update the modified object **************************
$json = @($pipeline) | ConvertTo-Json -Depth 99
$updatedef = Invoke-RestMethod -Uri $url -Method Put -Body $json -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
Reference: Definitions - Update
In the Agent Job3, set the custom conditions to:
eq(variables['RunAgentJob3'],'true')
Now, the Agent Job3 will run only if the agent Job2 succeeded.
Hope this helps.
来源:https://stackoverflow.com/questions/59370481/how-restrict-the-agent-job-to-run-only-if-specific-job-succeeded