仅在成功完成特定作业后如何限制代理作业运行 [英] How Restrict the Agent Job to Run only if Specific Job succeeded
问题描述
我在Azure Devops发布管道中有3个工作:
I have 3 Jobs in Azure Devops Release Pipeline :
- 代理人工作1
- 代理人工作2
- 代理人职位3
我要配置 Agent job2 ,即使 Agent job1 失败,它也应运行.
I want to configure Agent job2 In such a way that it should run even if Agent job1 Fails.
为此,我已将运行此作业的代理作业2 "属性设置为"",即使先前的作业失败.
for that, I have set Agent job2 property of Run this job to even if the previous job fails.
现在,我要配置 Agent job3 ,以便仅在 Agent job2 成功后
Now, I want to configure Agent job3 in such a way that it should run only if Agent job2 succeded
我需要在Agent Job3中进行哪些配置才能使其依赖于Agent Job2
What configuration I need to make in Agent Job3 to make it Dependant on Agent Job2
推荐答案
如何限制代理作业仅在特定作业成功后才能运行
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.
解决方法,我们可以在变量中将像 RunAgentJob3
这样的变量设置为 False
:
As workaround, we could set a variable like RunAgentJob3
to False
in the Variables:
然后,在第二个代理作业结束时添加一个内联Powershell任务,条件为所有先前的任务都成功后
,紧接在复制任务为调用REST API来更新变量,例如 RunAgentJob3
到 true
:
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"}
参考:定义-更新
在Agent Job3中,将自定义条件设置为:
In the Agent Job3, set the custom conditions to:
eq(variables['RunAgentJob3'],'true')
现在,只有在代理Job2成功的情况下,代理Job3才会运行.
Now, the Agent Job3 will run only if the agent Job2 succeeded.
希望这会有所帮助.
这篇关于仅在成功完成特定作业后如何限制代理作业运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!