skip to Main Content

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?

3

Answers


  1. Chosen as BEST ANSWER

    I was able to solve this by adding

    set -o pipefail

    In the start of the yaml file.


  2. 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.

    Login or Signup to reply.
  3. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search