I'm using Cloud Build as a CI/CD solution. My branching strategy follows this pattern: dev, stage and prod branches reflect exactly what I have in each of my environments. Any other branch is just a regular branch for development.
By following this pattern, I need to build/test in any branch except the main ones, and deploy only when pushes are in dev/stage/prod.
As Cloud Build doesn't support expressing this in a single YAML file, I have two: build.yaml and deploy.yaml.
Then I created two Build Triggers, like this:

The first works just fine, it triggers the steps described in deploy.yaml if anything is pushed to dev/stage/prod. But the second, although it accepts the RegExp and evaluates a preview of branches (notice you don't see the main branches):

When the build gets triggered (yes, it is triggered automatically!), it fails:

A bit of Googling tells me Go-lang (which supposedly is the back-end where this regexp is being evaluated here) does not support Lookahead in RegExp.
How can I solve this problem?
How can I solve this problem?
Here is how I did it, after trying negative look ahead first.
e.g. exclude branch master
^(([^m]|m($|[^a]|a($|[^s]|s($|[^t]|t($|[^e]|e($|[^r]))))))|master.+)
More details here.
Finally there is a new feature on cloud build to address this issue, basically on the triggers options there is a checkbox called Invert Regex, here is how it looks like:

This basically means that branches or tags matching the regex are excluded and by using ^(master)$ combined with this Invert Regex you will be able to match any branch that is NOT master.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With