Search code examples
gitgoogle-cloud-buildbitbucket-cloud

Bitbucket Cloud webhook to trigger branch specific Cloud Build URL


We building a CI/CD based on BitBucket and Google Cloud Build. We have one Cloud Build trigger per project: dev, staging, prod

How can we configure one or 3 webhook that based on the branch will trigger the specific Cloud Build? The only "workaround" we found is to have a Cloud Function which receives BitBucket trigger POST message and based on the JSON "name" field, triggers the specific Cloud Build. Is it the best way to move ahead?

Thanks


Solution

  • EDIT: Cloud Build now supports Bitbucket natively, see https://cloud.google.com/build/docs/release-notes#March_07_2024

    There are basically two approaches you can follow with Cloud Build alone, and more if you use a Cloud Function (or other) as an intermediate layer. Sathi Aiswarya pointed to the relevant document in his note.

    1. With 3 triggers (as you have), you'll need 3 webhooks, one for each trigger, and you can use a filter (as documented) to decide whether the trigger should fire based on the webhook payload.
    2. You could have a single trigger instead, which runs a build that inspects the payload to decide which build to run. You can either do this within your build script/steps, or as a standalone build that then triggers the build you really want to run. The latter is essentially the same approach as using a Cloud Function. Either way, you'll need to define substitutions to pass what you need from the payload to the build.