bashcontinuous-integrationdevopspipelinebamboo

Bamboo Pipeline Slack Messaged depending on status


I am trying to automate some slack Messages at the end of my daily Bamboo Pipeline runs.

What I am trying to figure out is, if there is a way to check for the pipeline status and post a message to Slack reflecting that?

i.e. if the pipeline fails I'd want a fail message, and vice versa.

I haven't found a way to retrieve the status of the pipeline inside of the script

Any ideas welcome.

Regards


Solution

  • Found a hidden undocumented variable that can be used to check for failure of the current job.

    #!/usr/bin/env bash
    
    ## bamboo does not catch some script failures unless this flag is set
    
    set -e
    
    TASK="CHECK BUILD STATUS"
    
    echo ================== START $TASK ==================
    
    ## bamboo_jobFailed is a boolean
    BUILD_STATUS=${bamboo_jobFailed}
    echo "BUILD_STATUS_failed?: $BUILD_STATUS"
    
    text=$"@here Hi all! There will be a delay in the Superset data refresh today, we are looking into it :slightly_smiling_face: Thank you!"
    
    if [[ "$BUILD_STATUS" == "false" ]]
    then
        echo "the build is passing"
    else
      echo "the build has failed"
      curl -X POST -H 'Content-type: application/json' --data "{\"text\" : \"$text\"}" https://hooks.slack.com/services/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
    fi
    
    echo =================== END $TASK ===================