Does anyone have experience setting up a CI pipeline in Jenkins for a monorepo that limits concurrent builds differently depending on the branch that the build is run on?
For some context, builds that run on a PR branch contain stages that are all run in parallel on separate agents. Builds that run on the master branch only contain one stage. I am using the Jenkins Throttle Concurrent Builds plugin to limit the number of concurrent builds.
Because our agents contain two executors (we don’t want to change the number of executors on each agent), I am using the throttle plugin on each stage. The throttle plugin is configured with a category that allows an unlimited number of builds but only allows one stage build per agent. Since each stage uses the same throttle category, each stage is only allowed to run on an agent that is not already running another stage, effectively solving our parallel stages build configuration.
The issue arises when trying to use the same category for our master branch builds. I want to limit the number of concurrent builds of the master branch stage to 1 while also preventing the master branch stage from being run on an agent that is also running a stage build of a PR.
I have tried creating a new category to use with the master branch stage that only allows 1 concurrent build and limits the number of builds on each agent to 1. But using only this category for the master branch stage does not respect the default category and the master branch stage builds on agents that might already be running a PR stage build. When I try to combine usage of both categories for the master branch stage, only the master branch category is respected and the previously described behavior persists.
Is there another plugin or way to limit concurrent builds that I am not aware of that better fits my use case that someone might know of?