Skip to content

Instantly share code, notes, and snippets.

@pono
Forked from abayer/gist:f748291f53b15621704f0ee01ae9d4f0
Last active August 10, 2018 17:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pono/8ab92fddb9461cd62e45923b910ce81f to your computer and use it in GitHub Desktop.
Save pono/8ab92fddb9461cd62e45923b910ce81f to your computer and use it in GitHub Desktop.
set number of executors to 2 for a node in Jenkins
import hudson.slaves.DumbSlave
# $NODENAME is the node name in Jenkins
# NODENAME is just a variable
# newNODENAME is another variable
def NODENAME = Jenkins.instance.getNodesObject().getNode("$NODENAME")
# The "2" here sets the number of executors to 2 on the node
def newNODENAME = new DumbSlave(
NODENAME.getNodeName(), NODENAME.getNodeDescription(), NODENAME.getRemoteFS(), "2", NODENAME.getMode(), NODENAME.getLabelString(), NODENAME.getLauncher(), NODENAME.getRetentionStrategy(), NODENAME.getNodeProperties().toList())
Jenkins.instance.getNodesObject().addNode(newNODENAME)
@gdmn
Copy link

gdmn commented May 26, 2017

def n = Jenkins.instance.getNodesObject().getNode("node-name-slave")
n.setNumExecutors(2)
Jenkins.instance.getNodesObject().removeNode(n)
Jenkins.instance.getNodesObject().addNode(n)

@burnettk
Copy link

i think this:

Jenkins.instance.getNodesObject().removeNode(n)
Jenkins.instance.getNodesObject().addNode(n)

can be replaced with this:

n.save()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment