CI/CD: Google Cloud Build — Regex Build Triggers
In this article we are going to cover creating build triggers using regex. This will be a short and straight to the point article not covering the full range of Google Cloud Build capabilities or the Google Cloud Platform.
If you’re interested in CI/CD pipelines, then please check out our other articles which cover varying topics. Here is a short list.
- CI/CD: Introduction
- Google Cloud Build — Create/Store Docker Images via GitHub Trigger
- Google Cloud Build — Custom Scripts
Alright, let’s jump in!
Open up the Google Cloud Build console
Navigate to your GCP project and find the Google Cloud Build service page. Then hit, Triggers.
Connect your GitHub account
We are using GitHub in this example, but as you can see below. Google Cloud Build supports BitBucket and Google Cloud Source Repository.
Choose your desired Repository
You can filter repositories depending on the size of your GitHub account. I’m using a simple repository that isn’t being used for the setup as we won’t be getting into creating the full CI/CD in this article. If you would like to see that check the articles at the top for more information.
Specify your branch regex
This is a simple case that might raise a question. Why are you writing a mini article to cover this one topic? Well, we had a client who was using a branching strategy that consisted of dev-[dev-name]. Which caused Google Cloud Build to deploy new code to our development application every time one of the devs pushed from any branch that had dev in it. However, with the regex below or more complicated regex we can ensure that we are building exactly what we intend too.
Well now we are limiting the deployments to only the dev branch. But, we can take it further and even have a whole separate trigger on all the dev-[dev-name] branches which will run a completely different build.
Now for instance if a developer pushed their branch (dev-ryan), then this separate Google Cloud Build Trigger would only build and test. Not deploy to the live development environment. Allowing for us to reuse the same knowledge, skills, and process to accomplish both a full CI/CD and a CI for feature branches.
Note: This is not a recommended branching strategy, but meant to showcase a small feature of Google Cloud Build which can be quite powerful.
At Serverless Guru, we have a lot of experience in building CI/CD pipelines. We work with companies and internal employees to help create reusable patterns and build automation practices which can be applied across the organization. We are engineers first, which is important.
Lets keep the party going..
If you like this article and want to see more content like this. Please give us a follow here on Medium or share on Twitter @serverlessgurux! Finally, if you want to learn about Serverless then you should definitely check out our courses at training.serverlessguru.com.
What would you like to see next?
We will be releasing new articles about various technologies like Serverless, Docker, Kubernetes, GCP, AWS, Go, Python, and NodeJS to name a few.
If you have any topics you want to see. Comment below because then we can improve and bring more value.
Founder — Serverless Guru
LinkedIn — @ryanjonesirl
Twitter — @ryanjonesirl
Thanks for reading 😃