Throttling Jenkins pipeline builds but still allow manually starting builds when throttled - jenkins

How do you throttle Jenkins pipeline build so the queue doesn't get filled with multiple pipeline jobs but still allow someone to force start a build if they need it?
Currently, the throttle builds property will prevent the job from starting at all (during the throttling period) through the jenkins web interface. "Execute concurrent builds if necessary" or "Quiet Period" may be a better option but I cannot set that in the Jenkinsfile.

Related

Jenkins Gitlab multi-branch concurrent builds

Anyone has idea how to limit number of concurrent builds on Jenkins for multi-branch pipeline?
I was searching out but almost every approach was about putting properties([disableConcurrentBuilds()]) which doesn't work in my case.
We use resource lock for unit tests, so they don't overlap. In my case no matter how many build executors I have they will just wait on lock to be released so they continue one by one while reserving build slot instead waiting in queue. I found some similar post:
Jenkins limit multibranch
for gitlab pipelines use parameter resource_group for create a resource group that ensures a job is mutually exclusive across different pipelines for the same project:
https://docs.gitlab.com/ee/ci/yaml/#resource_group
for jenkins: plugin and parameter "Block build if certain jobs are running"
https://plugins.jenkins.io/build-blocker-plugin/

Make pipeline job wait until previous is built

How to make jenkins pipeline script programmatically wait until previous/last job execution is currently running or succeeded?
There is option to disable concurrent builds, but that is a really bad option that will stack commits.

Force Jenkins to run only one pipeline job and put rest all in queue

I would like to build only one project at a time in entire jenkins server. I have tried Jenkins throttle concurrent plugin and lockable resource plugin but no luck. As lockable resource plugin doesn't give me option to lock in pipeline job.
I have 3 Jenkins pipeline jobs (job have pipeline script):
JOB1
JOB2
JOB3
which has some common thing at beginning of the job (clearing content).
Running one by one manually doesn't have any problem if job completed but if JOB1 is building and JOB2 starts in between then it interrupts to JOB1 and build fails for JOB1.
Even when I start jobs using CLI, you never know which job might be running. So, I'm looking for solution to block JOBY if JOBX is running (X, Y can be 1,2 or 3) and allow only one job to run in entire Jenkins server. Like I said, throttle concurrent plugin gives customization option only for respective job instead of for multiple jobs?
Can anyone suggest some solution for multi pipeline jobs block to run only once?
Install Build Blocker Plugin
In configuration of JOBY check "Block build if certain jobs are running".
Put JOBX name in Blocking Jobs text area, each job on new line.
Note, you can also use regex to define in single line jobs having the same prefix but ending with different numbers.

Run certain Jenkins jobs alone on a node

There some Jenkins jobs that have very high memory requirements. With the aim to avoid memory-related issues I'd like to configure these jobs to block execution of any other jobs from any project on the same node while they are running.
I played with Throttle Concurrent Builds Plugin, but it looks to limit jobs only from the same project. Other plugin - Build Blocker Plugin doesn't block other jobs to be run while the configured job is running.
Are there any plugins that allow to configure "single process" mode for some jobs?
In the "Throttle Concurrent Builds" Plugin there is a "Multi-Project Throttle Categories" option. Make a category "memory hogs" and add all jobs using a lot of memory to that category, than configure limits with "Throttle this project as part of one or more categories"

How to have all jobs of a build be executed exclusively on the same node?

I have a Jenkins server with half a dozen builds. Each of these builds is composed of a parent job that triggers anywhere between 4 and 6 smaller jobs that run in parallel. I use the EC2 plugin to keep the number of active slaves in line with the number of queued builds. Or in other words, slaves are coming and going all the time. Each slave has 7 executors (parent job + max(4, 6)).
It is absolutely crucial that all jobs of a build are executed on the same machine. I also cannot allow any jobs from build A to execute on a machine that has jobs from build B running.
What I'm looking for is a way that prevents Jenkins from using any inactive executors of a node as long as any jobs from a previous build are still active on it.
I've spent the day experimenting with a combination of the Throttle Concurrent Builds Plugin and the NodeLabel Parameter Plugin. Unfortunately, there seems to be a bug somewhere that causes throttled builds to not contribute to the Load Statistics of a slave. This in turn means that throttled build will never trigger Jenkins to spin up additional slaves. Obviously this is totally unacceptable.
You can try and use "This build is parameterized"
and pass the $NODE_NAME as a parameter between the builds and then use it at the "Restrict where this project can be run"

Resources