Search code examples
google-cloud-platformgoogle-cloud-pubsubgoogle-cloud-build

Using Google Cloud Build and Pub/Sub triggers to clone and run a repository


Is it possible for me to use a Google Cloud Build trigger that triggers upon Google Pub/Sub events to pull down a repository and build the code for it? Or is this only possible through Cloud Build build triggers?

If it is possible to use Pub/Sub triggers to build a repository in Cloud Build, will I need to pull down the repository with a dedicated step in the Cloud Build yaml?


Solution

  • You can run Cloud Build on different events. PubSub event is one of them. When you configure your event, it's not mandatory to mention the Git repository. But, in that case, you have to mention the cloudbuild.yaml in the trigger (to let Cloud Build knowing what it has to do during the build).

    In that cloudbuild.yaml file, you have to specifiy your steps. Because you have no repository attached to the trigger, your first step is to pull the code in Cloud Build and then build what you want.

    If you want something super generic, you can even get the repository info in the PubSub message!


    Pro tips: Because you can run a Cloud Build on a PubSub message without a Git repository attached, you can also imagine running something else than a "code build" with Cloud Build.

    For instance, before the creation of Cloud Run jobs, I ran all my serverless jobs like that: ingest data, transform data,....