I have a single repo with several (java/gradle
) projects:
project-a/
project-b/
project-c/
I would like to create a matrix build configuration, with one build per project. And I only want to build that project if there have been changes to it.
Is this possible?
I can easily create a script that checks if a folder has been affected by using $TRAVIS_COMMIT_RANGE
. But how would I use this in .travis.yml
?
There's an issue in Travis for adding support for include/exclude paths for when to trigger builds. With matrix support, this would solve my issue.
You can use the " when " block combined with the built in "changeset" condition to conditionally run only certain stages of your monorepo's pipeline. From the when.changeset documentation: changeset- Executes the stage if the build’s SCM changeset contains one or more files matching the given string or glob.
Whether a monorepo brings more benefits than drawbacks to a project depends strongly on the project’s structure and organization. Simple rule-of-thumbs are One repo per team or Release it together, keep it together.
If you migrate your multirepo to a monorepo, or if your project is getting big enough to consider running only part of continuous integration (CI) - then it can make sense to run only those parts of CI that could have been affected by the change.
Based on the collection of monorepo stories, we can define a set of best practices: Define a unified directory organization for easy discovery. Maintain branch hygiene. Keep branches small, consider adopting trunk-based development. Use pinned dependencies for every project.
You essentially ask about a conditional build in one form or another. Unfortunately the documentation about conditional builds states that
Jobs created via matrix expansion currently cannot have conditions.
... and even if it supported that, I don't see any easy way to check for a commit path in the list of supported conditions.
Nonetheless it is possible to achieve that process with their API. You can create a build configuration which aims to just run your script, and check which subproject needs to be built now. This meta build script can trigger a travis build via the API. On that doc page you can find an example of how to trigger a particular job from your matrix.
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