Cloud Build is a powerful, scalable, and cheap way to run your CI/CD builds, but the triggers have some limitations, like branch exclusions.
For example, perhaps you have triggers to:
- Build/deploy the tags to production
- Build/deploy the `master branch to integration
- Build/test feature branches on NOT
master|develop
You can handle cases 1 & 2 with branch
and tag
triggers, but case 3 requires regex exclusions. Unfortunately, this is not an option in Cloud Build triggers.
Regex Contortions to the Rescue
It’s well know that the solution to a regex problem is always more regex.
So, using some negative classes (a bunch of them actually), we can make a NOT master
trigger regex for Cloud Build.
e.g. ^(([^m]|m($|[^a]|a($|[^s]|s($|[^t]|t($|[^e]|e($|[^r]))))))|master.+)
1
Don’t Forget to Match the Entire Branch
Make sure you match the entire branch name, unless you want to match multiple branches.
e.g. “^master$
” to match master, not “master
”
Otherwise, when Jill checks in her feature branch jill-css-masterpiece
, it will automatically get sent to integration or worse 2.
Match it like you mean it 😉.