8

I have a single Cloud Source Repository with multiple projects. I am able to create a cloudbuild.yaml file in the repo root that builds all projects. However, I don't want to have a build trigger that rebuilds all of the projects since most commits will be for a single project. Ideally I would like to have a cloudbuild.yaml file in each project subdirectory and a build trigger that detects changes in the project subdirectory of the repository. Is something like this possible?

As a possible workaround, I believe I may be able to keep my cloudbuild.yaml in the repository root and create a custom step that will get the commit sha (via the COMMIT_SHA substitution) and then get the list of files committed (via "git show --name-only --pretty=format: $COMMIT_SHA") to determine which project should be built and what image should be created. An alternative may be to have a tagging naming convention that will contain the project name and basing the trigger on that but I don't want to tag each commit.

Note, it seems like build triggers work very well when you have multiple repos but we made the decision to go with a mono repo and I don't want to rehash that debate in this question. I'd like to understand how to best use the Build Triggers in a mono repo.

Josh
  • 81
  • 1
  • Thanks for this useful feedback. Today, triggers can only be run from the root of the repo, and this is a known limitation of the service. Allowing triggers to be run from subdirectories would help bring better support for monorepos like yours. Unfortunately we don't have a good story for this today. Of the two options you describe, the tagging scheme seems slightly better, though I agree it's not optimal. – Jason Hall Jun 27 '17 at 17:17
  • Did you found a solution to this limitation? cc @JasonHall has anything changed? – perrohunter Sep 09 '18 at 23:07
  • GCB triggers can now define paths that should and should not trigger a build, which can help with this somewhat. Define a trigger that builds Component A from source dir for A, and only triggers on changes to that dir, etc. – Jason Hall Sep 11 '18 at 14:04

0 Answers0