构建结果是只读的,构建完成后无法更新。但是,您可以查看以下解决方法来消除 Devops 门户中的失败标志(红十字)。
1, Use continueOnError
对于任务在StopApplication
工作。对于下面的例子:
jobs:
- deployment: StopApplication
...
steps:
- task: taskName
...
continueOnError: true
当 continueOnError 属性设置为 true 时。管道的结果将设置为SucceededWithIssues
当任务失败时。您将看到一个感叹号而不是红十字
您还需要更改为condition
为了工作ManualIntervation
.
然后改变工作条件ManualIntervation
检查标志变量是否设置为 true。见下文:
- job: ManualIntervation
dependsOn: StopApplication
condition: eq(dependencies.StopApplication.result, 'SucceededWithIssues')
2、另一种解决方法是将StopApplication
与不同管道中的其他工作的工作。
您需要创建两个管道。第一个管道只有StopApplication
工作。第二个管道包含其余作业。并使用第一个管道触发第二个管道rest api https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run%20pipeline?view=azure-devops-rest-6.1.
在第一条管道中。在失败的任务之后执行一个 powershell 任务来检查作业状态并使用 REST API 触发第二个管道。请参见下面的示例:
- powershell: |
$body = @{
templateParameters=@{
ManualIntervation= "false"
}
}
if("$(Agent.JobStatus)" -eq "Failed"){
$body.templateParameters.ManualIntervation='true'
}
$url = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/pipelines/{second-pipelineId}/runs?api-version=6.1-preview.1"
$result5 = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Bearer $(system.accesstoken)"} -Method post -Body (convertto-json $body) -ContentType "application/json"
condition: always() #always run this task
然后在第二个管道中定义一个 ManualIntervation
并设置工作条件ManualIntervation
见下文:
parameters:
- name: ManualIntervation
type: string
default: false
...
- job: ManualIntervation
dependsOn: StopApplication
condition: eq('${{parameters.ManualIntervation}}', 'true')
当第一个管道执行时。 powershell任务将触发第二个管道将模板参数请求体覆盖参数ManualIntervation
在第二条管道中。如果ManualIntervation
是真的。然后将执行 ManualIntervation 作业。
这样,即使第一个管道失败,第二个管道也会成功。