'Does Google Cloud Build tag trigger apply to all branches by default?

When choosing Tag based trigger in Google Cloud Build, does that mean that any branch with that tag pushed will trigger the pipeline? How can we restrict it to a specific branch, i.e. only tags pushed to a specific branch will trigger the pipeline (tags pushed to develop branch for example)?



Solution 1:[1]

As of Feb. 2022, I believe the answer to your question is (unfortunately) yes, any time you push a commit with the given tag, regardless of the branch, the build will run.

As to your second question, it doesn't appear that there are any built-in filtering options for both branches and tags. (There is no mention of this ability in the documentation for creating triggers.) There is a way to skip builds by including [skip ci] in your commit message, but that's not ideal for automation. Depending on the constraints you have on your branch structure or tagging scheme; if those are flexible, you might be able to use a different set of tags on your develop branch.

One last option would be to add a bash build step at the start of the build to check the name of the branch (built-in substitution BRANCH_NAME) and kill it if it doesn't match some criteria. It's a bit hacky, but that's sometimes necessary with Cloud Build.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tanner Stern