Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build Trigger doesn't recognize Negative Lookahead in RegExp on Cloud Build

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:

enter image description here

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):

enter image description here

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

enter image description here

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?

like image 363
larruda Avatar asked Mar 06 '23 03:03

larruda


2 Answers

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.

like image 160
Joseph Lust Avatar answered May 13 '23 19:05

Joseph Lust


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:

invert-regex-checkbox

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.

like image 25
Jhuliano Moreno Avatar answered May 13 '23 18:05

Jhuliano Moreno