Locking a slave in Jenkins until a particular job is run - jenkins

There is a requirement in our CI set up( We are using Jenkins as CI ), where in we need to lock the slave for a particular time until a particular or high priority job finishes on Jenkins. This is to ensure that no other jobs should run on this slave.
Once the Job starts execution then it needs to be ensured that no other jobs should run on that slave?
Do we have any Jenkins plugins that can help us to lock the slave if a job is running and then release the slave node to be used by other jobs once the job finishes(fail or success).?

use Heavy Job Plugin https://wiki.jenkins-ci.org/display/JENKINS/Heavy+Job+Plugin and set the job weight equal the number of executors on your slave. Then no other job can run on this slave.

Related

Prevent jobs from running on jenkins slave if a job of slave's own pipeline is running on it

I have master jenkins and slave jenkins. I hav kept slave jenkins no of build executors as 1. Slave Jenkins also has 1 pipeline (Lets say pipeline A).
lets suppose a job from slave jenkins' own pipeline is running right now (Job A). I schedule a job from the master jenkins for slave jenkins (Job B).
I dont want Job B to run while job A is running as both jobs use shared resources.
Right now, Job B runs in parallel with Job A, which is causing Job A to fail.
How to do that?
Thanks!
Your implementation is a bit tricky since you are talking about 2 separate machines with 2 separate Jenkins instances. One option is to get rid of the Jenkins instance in the slave machine and move the Jenkins job that runs on it to the master machine. Then, you can schedule the job to use the resources of the slave machine while being managed by the master machine. If you do that, no further configuration will be needed since you have set the number of executors to 1.
If that is not possible, the other option is to find a way for them to communicate with each other that a build is running. Consider the third point of this answer. You can have a variable in a database somewhere and when one job starts, it updates the variable. Before the second job starts, it has to poll the variable to see if there is a job already running. If yes, the build doesn't start, if no, build starts and updates the variable.
Another less elegant solution is to simply have a text file in a location accessible to both machines and write the variable data into that instead of a database.
One way to do this is by using the Lockable Resources Plugin.

How to scale Jenkins slaves according to Build Queue on Kubernetes Plugin

I'm running on the Jenkins pipeline, so I have set the value to Time in minutes to retain agent when idle in slave configuration after I have run my jobs my slave but when the other job needs to run if a slave agent is full, jobs are waiting on Build Queue.
How I can scale the my slave count on Jenkins with Kubernetes plugin?
You're looking for the Container Cap setting, if you're using the Jenkins Configuration as Code (JCasC) plugin this is configured via the containerCapStr key.

Jenkins stop a job from running on a node when a certain job is already running

I have just setup auto-scaled slave nodes on Jenkins and to inject env vars, secrets and some other configurations to the slaves I am running a provisioning Jenkins job on each slave when it starts up.
However, the provisioning job can take around a minute to complete. So if a job spins up a Slave node which hasn't been provisioned it could fail. I know I could add a block when the provision job is running to EVERY job but that doesn't sound too ideal...
Is there a way that I can easily block all other jobs on the node until the provision job has finished running?

Initiate Jenkins job on salve X while it’s running on slave Y

Let’s say I have Jenkins job that should be running on a slave for several hours, is there a way that while job is running to run it but this time on a different slave so same job will run on 2 salves in parallel ?
Currently when I try to do that I get something like that:
(pending—Build # is already in progress )
You will need to check "Execute concurrent builds" in the job.
You will also have to install https://wiki.jenkins-ci.org/display/JENKINS/Throttle+Concurrent+Builds+Plugin
This will allow you to specify how many runs you want your job to execute concurrently and how many runs per slave - so you won't have to limit the executors on your slaves to one, and that way you can always assure there will be no 2 parallel runs on one slave.
Good luck!

Use different slave for same job on different runs in Jenkins

How do we make Jenkins start the Job in a different slave every time it is run. It usually picks the slave which is free, but what if we wish to run the jobs in a different slave environment.
When you configure your job you should tick the box that says "Restrict where this project can be run" and add the name of the specific node you want your job to run on.

Resources