Introduction
Sometimes failing scripts are not failing the task when they should. And sometimes a failing command should not fail the task. How to handle these situations by Continue Azure Pipeline on failed task?
In Sometimes, you many have some Pipeline Tasks which may be dependent on external reference which may chance to fail at any time. In these scenarios, if the Task is failing (or may be failing intermittently) due to any issue in external reference, your entire pipeline would fail. You don’t have any insights about when the bug would get fixed. So in the above case, you though to run the pipeline if any issue in the that task and you want to ensure if any issue in future for this task then it wont lead to pipeline failure.
This simple technique can be used in scenarios where you have a non-mandatory task that’s failing intermittently and you want to continue the execution of the pipeline
Solution :
In this case, it absolutely makes sense to continue the execution of the next set of Tasks (Continue Azure Pipeline on failed task) . In this post, we are going to learn how to continue the execution of the pipeline if a particular Task has failed by using ContinueOnError/failOnStderr/failOnStandardError property.
using ContinueOnError attribute in Powershell/script Task
Let’s build a pipeline with few tasks where we simulate and error in one of the tasks as shown below. As shown in the below code, the following points to be noted.
The task named “continueOnError Task”, an intentional added targetType: ‘filePath’ but used the ‘inline’ script instead of mapping with script file to simulate an error. Second, attribute called continueOnError has bee added to ignore if there any errors while executing the pipeline.
steps: - task: Powershell@2 displayName: "continueOnError Task" continueOnError: true inputs: ScriptType: InlineScript Inline: | Write-Hosts "Continue if any issue here" - task: Powershell@2 displayName: "No Error Task" continueOnError: true inputs: targetType: 'inline' Inline: | Write-Host "Block if any issue here"
Now, when you run the pipeline, an indication about the error for the Task is shown and the execution will carry forward as shown below.
Like PowerShell task, you can continue error in other tasks as well as shown in bellow (click below link reference to know about other tasks).
- Command Line task covers failOnStderr
- Azure CLI task covers failOnStandardError
- Task types & usage covers continueOnError
Summary:
In this this post, we have learnt how to continue the execution of the pipeline in spite-of having an error in one of the tasks that is Continue Azure Pipeline on failed task. This simple technique can be used in scenarios where you have a non-mandatory task that’s failing intermittently and you want to continue the execution of the pipeline.