Reputation: 783
Task is running on Node.
Part of the yaml file for the pipeline is:
steps:
- script: |
#!/bin/bash
./plan.sh
displayName: "example deploy"
continueOnError: false
Now, when sometimes the ./plan.sh script fails: but it still shows as a success (green tick) in the pipeline. See below:
How do I make it show a "failed" red cross whenever it fails?
Upvotes: 2
Views: 2516
Reputation: 783
I was able to solve this by adding
set -o pipefail
In the start of the yaml file.
Upvotes: 0
Reputation: 7251
What you are doing now is actually calling the bash script file from PowerShell. Your way of writing it cannot capture the error message. The correct way is as follows:
plan2.sh
xxx
pipeline YAML definition:
trigger:
- none
pool:
vmImage: ubuntu-latest
steps:
- script: |
bash $(System.DefaultWorkingDirectory)/plan2.sh
displayName: "example deploy"
continueOnError: false
Successfully get the issue:
But usually, we use the bash task directly to run the bash script.
plan.sh
{
xxx
# Your code here.
} || {
# save log for exception
echo some error output here.
exit 1
}
pipeline YAML definition part:
steps:
- task: Bash@3
displayName: 'Bash Script'
inputs:
targetType: filePath
filePath: ./plan.sh
Successfully get the issue:
Upvotes: 2
Reputation: 2066
For your script step to signal failure, you need to make the script as a whole return a non-0 exit code. You may need some conditional logic in your script, checking the exit code from plan.sh after it returns.
Upvotes: 1