I have the problem that I need to run a job on a slave exclusively,
meaning without any other jobs running on that slave at the same time. I
know there's the "Exclusive Execution" plugin, but that is taking the
master offline during that time, which I find rather drastic. I'd like
to do this in a less disruptive way with a Groovy system script:

- Job starts on Slave and first sets its number of executors with
  setNumExecutors() to '1'. This will not interrupt running jobs, but
  will make the slave not accept any new ones, which is exactly what I'd
  like.

- Job waits until all other jobs on the slave are finished (by checking
  countBusy())

- Job does whatever it needs to do exclusively.

- Job sets number of executors to old value and exits.

I've pretty much figured it out, except for one thing: setting the
number of executors on a slave. I tried doing

Hudson.instance.getComputer("SlaveName").setNumExecutors(1)

but that does not work, since 'SlaveComputer' does not implement this
method:

  groovy.lang.MissingMethodException: No signature of method:
     hudson.slaves.SlaveComputer.setNumExecutors() is applicable for
     argument types: (java.lang.Integer) values: [2]
  Possible solutions: getNumExecutors(), getExecutors()

I can only call 'setNumExecutors' on the Jenkins instance itself, but
that will always apply to the master node.

As an alternative, I did set the slave temporarily offline, which is
possible with the 'Computer' object, but that doesn't play well with
jobs which are already running: while they don't get aborted, it seems
those jobs can often not exit cleanly when they still need to work on
the remote file system.

Any ideas?

Cheers,
David

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to