Looking for Senior AWS Serverless Architects & Engineers?
Let's TalkIn 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.
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.