1

I have two webhook (A, B) on the same repository that will invoke two external pipelines.
What I expect is if a specific file [sampleB.txt] changes, only webhook B will be invoked.

The issue is: the Bitbucket webhook message payload does not send the files changed.
Is there any workaround?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
user3454
  • 31
  • 1
  • 4

1 Answers1

0

The BitBucket repository event payload for a push include information about the commits pushed.

And you can use GET /repositories/{username}/{repo_slug}/diff/{spec} to get raw, git-style diff for either a single commit (diffed against its first parent)

Your listener should call a script which will process the webhook payload.

The payload will contain information about the commit, such as the commit hash.

  • Use the Bitbucket API to fetch the raw, git-style diff for the given commit using the following endpoint:

    GET https://api.bitbucket.org/2.0/repositories/{username}/{repo_slug}/diff/{commit_hash}

  • Parse the raw diff response to extract the list of changed files. The diff lines starting with 'diff --git' contain the file paths.
    For example, a line like this:

    diff --git a/sampleA.txt b/sampleA.txt
    

    Indicates that 'sampleA.txt' is one of the changed files.

  • Iterate through the list of changed files and check if 'sampleB.txt' is present.

    If 'sampleB.txt' is present in the list of changed files, conditionally trigger the pipeline associated with webhook B.
    If not, proceed with the pipeline associated with webhook A or skip the pipeline execution as per your requirement.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250