Search code examples
jenkinsgoogle-cloud-platformgoogle-cloud-build

Is there an equivalent of Jenkins shared libraries in GCP Cloud Build?


I have several simple cloudbuild.yaml files that exist in several different projects that all do very similar things (i.e. create a Docker image, push it to some artifact registry, etc). I'm wondering if there's a way to put all the boilerplate cloudbuild.yaml stuff into a single place, and have other cloudbuild.yaml files extend that base cloudbuild.yaml.

I know that Jenkins Shared Libraries' feature works similarly to this - is there an equivalent feature in GCP Cloud Build? If not, is there a recommended pattern or anything I should be using to remove boilerplate code from my cloudbuild.yaml files (i.e., maybe I could be using PubSub to trigger other Cloud Build pipelines where the majority of code is saved, or something)?


Solution

  • Jenkins Shared Libraries, which eliminate boilerplate code from cloudbuild.yaml files and promote reuse, do not directly exist in Google Cloud Build. However, you can use the following strategies:

    Build Triggers and Pub/Sub - To start a central Cloud Build pipeline with shared code from different project-specific cloudbuild.yaml files, use Cloud Build Triggers and Pub/Sub.

    Custom Build - Utilise a custom build step in each cloudbuild.yaml file to carry out common procedures that have been defined in a different script or Dockerfile.

    Cloud Build Configurations in YAML - During the construction process, merge common configurations with project-specific configurations from a YAML file.

    Cloud Build Community Builders - Reuse frequently used settings by using shared build steps that the community has contributed.

    When using shared configurations, be sure to adhere to security best practises, and keep up with the most recent Cloud Build features by reading official announcements and documentation in Google Cloud Build Release Notes