The build result is read-only and cannot be updated after the build is completed. However, You can check out below workarounds to get rid of the Failed sign(Red Cross) in Devops portal.
1, Use continueOnError
for the task in StopApplication
job. For below example:
jobs:
- deployment: StopApplication
...
steps:
- task: taskName
...
continueOnError: true
When the continueOnError attribute is set to true. The pipeline's result will be set to SucceededWithIssues
when the task failed. You will have a exclamation mark instead of red Cross
You also need to change to the condition
for job ManualIntervation
.
Then change the condition for job ManualIntervation
to check if the flag variable was set to true. See below:
- job: ManualIntervation
dependsOn: StopApplication
condition: eq(dependencies.StopApplication.result, 'SucceededWithIssues')
2, Another workaround is to separate the StopApplication
job from the others jobs in a different pipeline.
You need to create two pipelines. The first pipeline only have StopApplication
job. The second pipeline contains the rest of the jobs. And trigger the second pipeline from the first pipeline using rest api.
In the First pipeline. And a powershell task after the failed task to check if the job status and trigger the second pipeline using rest api. See below example:
- 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
Then in the second pipeline define a runtime parameter ManualIntervation
and set the condition for job ManualIntervation
see below:
parameters:
- name: ManualIntervation
type: string
default: false
...
- job: ManualIntervation
dependsOn: StopApplication
condition: eq('${{parameters.ManualIntervation}}', 'true')
When the first pipeline is executed. The powershell task will be trigger the second pipeline will the template parameter request body to override the parameter ManualIntervation
in the second pipeline. If the ManualIntervation
is true. Then the ManualIntervation job will be executed.
So that the second pipeline will be succeeded even if the first pipeline failed.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…