CI/CD: Google Cloud Build — Regex Build Triggers

Jan 19 · 4 min read

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.

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.

More advanced

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 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.

Additional Content:

What does Serverless Guru do?

Serverless Guru helps companies build scalable and cost-effective applications on the cloud. We help train companies on how to leverage IAC, serverless, and cloud-native services. We help migrate existing applications to the cloud and optimize existing applications on the cloud to be more cost-effective. We are a Serverless development partner and an AWS Consulting partner.

What did we miss?

When you leave your answer make sure to either comment below or tweet your answer to @serverlessgurux on Twitter.

Ryan Jones

Founder — Serverless Guru

LinkedIn — @ryanjonesirl

Twitter — @ryanjonesirl

Thanks for reading 😃

If you would like to learn more about Serverless Guru, please follow us on Medium, Twitter, Instagram, Facebook, or LinkedIn!

Serverless Guru

Serverless Guru is a cloud consulting and training company specializing in Serverless development and cloud optimization.

Serverless Guru

Written by

Exploring the unknown and helping elevate the entire community through written word.

Serverless Guru

Serverless Guru is a cloud consulting and training company specializing in Serverless development and cloud optimization.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade