Search code examples
githubgoogle-cloud-platformgoogle-cloud-build

How to make Coogle Cloud Build trigger changes from all commits in branch


We use Google Cloud Build to run different tests for our Github repository when we push a branch. Our problem is that only the last commit in the branch seems to affect which triggers are run.

E.g. say our repository looks like this:

./client/<client code>
./server/<server code>

and in our two triggers we specify the Included files filter like this:

  • trigger 1: Included files: client/**
  • trigger 2: Included files: server/**

the problem is that only the last commit in the branch that should trigger builds affects which triggers to run.

To illustrate the problem: say we push a branch with the following commits:

  • Commit 1: <Changes to client/foo.js>
  • Commit 2: <Changes to server/bar.scala>

only "trigger 2" is run. And what we want is that both triggers are run, since we want to run tests for all the changes introduced by our branch.

Is there any way to get GCB to "see" all the changes in the branch that is pushed, when deciding which triggers to run? The obvious quick-fix is to create branches with single commits, which makes all the triggers run, but is less than ideal from the perspective of our git workflow.


Solution

  • With the trigger type set to "push to a branch", git is not able to track the changes made to all the branch but only to the last commit as you described.

    To accomplish this, you must use Pull Requests to trigger the build. When creating a pull request, git will than be able to track the changes appropriately and your tests will be run as you expected. So change the event that triggers your build to "Pull Request" and than create a pull request from your branch to trigger the build and therefore your tests.