devgirl
devgirl

Reputation: 783

Azure DevOps Pipeline task fails but still shows green (sucess)

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: enter image description here

How do I make it show a "failed" red cross whenever it fails?

Upvotes: 2

Views: 2516

Answers (3)

devgirl
devgirl

Reputation: 783

I was able to solve this by adding

set -o pipefail

In the start of the yaml file.

Upvotes: 0

Bowman Zhu
Bowman Zhu

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:

enter image description here

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:

enter image description here

Upvotes: 2

Conrad Albrecht
Conrad Albrecht

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

Related Questions