1

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!

  • The number of executors relate directly to the number of jobs allowed to run at a given time. If you have set the number of executors in the slave to 1, then Jenkins should not be running multiple jobs at once on that agent. Do you mean to say that Job A runs in the slave while Job B runs in master, and they both use the same resources? – M B Feb 03 '23 at 03:40
  • okay so, job A is part of a project created on the slave and job B is coming from master to the slave. I want to restrict both jobs running at the same time. – Kartik Tanwar Feb 03 '23 at 03:45
  • How do you mean that project A is created on the slave? Do you have 2 Jenkins instances, 1 on master and 1 on slave? – M B Feb 03 '23 at 03:55
  • Yes correct mate! So both the instances can run jobs and jobs of both instances use shared resources. How to make sure if 1st job of 1st instance is running then job of 2nd instance doesn't run? – Kartik Tanwar Feb 05 '23 at 19:16

2 Answers2

1

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.

M B
  • 2,700
  • 2
  • 15
  • 20
0

One way to do this is by using the Lockable Resources Plugin.

ycr
  • 12,828
  • 2
  • 25
  • 45