DNielsen
DNielsen

Reputation: 43

How to trigger a webhook inside Bitbucket Pipelines

I'm trying to figure out if there is a way to trigger a webhook inside a bitbucket-pipelines.yml file? I've looked around and the closest I've found to an answer is the answer located here Bitbucket webhook trigger after pipeline completes successfully. But the answer just says to "add the necessary commands", but no mention of what those commands are.

Just wondering if someone can elaborate as to what those commands would be to accomplish this?

The problem in case you're wondering that I'm trying to solve is we have a webhook that currently runs whenever a PR is created, which is fine. However, we have build steps that are run in our pipeline that can fail (tests, linting, etc...), and we don't want this webhook to run if the build fails. So my idea was to initiate the webhook at the end of the pipeline, so that if the build fails it won't initiate the webhook.

Upvotes: 2

Views: 2796

Answers (1)

Alexander Zhukov
Alexander Zhukov

Reputation: 4547

You can also use an after-script in your step configuration. There is a BITBUCKET_EXIT_CODE variable available that you can use to determine the build result status.

pipelines:
  default:
    - step:
        name: Build and test
        script:
          - npm install
          - npm test
        after-script:
          - if [[ $BITBUCKET_EXIT_CODE -eq 0 ]]; then curl https://webhook-url ; else echo "Step failed"; fi

Upvotes: 4

Related Questions