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 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.
- Industry Predictions for 2019
- Best Practices for Serverless Development
- Serverless CI/CD
- Serverless Web Applications — AWS v GCP
- Serverless Impact, Developer Velocity
- Guide, First Serverless Project
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.
Founder — Serverless Guru
LinkedIn — @ryanjonesirl
Twitter — @ryanjonesirl
Thanks for reading 😃