Search code examples
bitbucketslackbitbucket-pipelines

How to get slack notification when a certain step passes / fails in bitbucket pipeline?


I have E2E tests in one of the bitbucket repository and I created a docker image to run those tests in another repository. I am able to run the tests using image but I also want to get the slack notifications when the certain E2E step in the pipeline passes / fails.

I don't want to get slack notifications for the whole pipeline. I just want it for the e2e tests when they run in other repositories.

enter image description here

Thanks in advance!


Solution

  • I have managed to sort it by having after script:

    after-script:
              - echo $BITBUCKET_EXIT_CODE
              - BUILD_STATUS="successful"
      
    
            - if [[ BITBUCKET_EXIT_CODE -eq 0]]; then exit 0; else 
    BUILD_STATUS="failed"; fi 
                  - echo "Step ${BUILD_STATUS}"
                  - pipe: atlassian/slack-notify:2.0.0
                    variables:
                      WEBHOOK_URL: $WEBHOOK_URL
                      MESSAGE: The E2E tests are "${BUILD_STATUS}".