I have a Jenkins pipeline which uses 2 nodes, each node configured to have 3 executors.
is there a way to pick a specific executor to run the pipline/stage?
i know picking the node can be done using:
pipeline { agent { label XXX } stages{ stage("Build") { agent { label YYY } ...} }
but is there a way to pick the executor? is there any plugin to support such functionality?
I found that checking if executor is idle or busy can be performed using:
def nodeInstance = Jenkins.instance.getNode(nodeName)
def computer = nodeInstance.toComputer()
computer.executors.each { executor ->
def idleState = executor.isIdle()
... }
but no mention of how picking them.
Jenkins allows to configure the number of executors in attempt to utilize the build agent resources more efficiently.
From Managing Nodes:
So in fact it's quite an abstract entity. You're not supposed to select a specific executor in your pipelines, thus you cannot do it.
However, there are some cases when a reference to the executor ID could be used.
Generally, having multiple executors on the same node can lead to resource conflicts. Say, you have a Maven
$HOME/.m2repository on the agent, and you're in a team that develops a Java project. If all your builds use the same repository, and some of them happen to be built on the same agent by different executors, they:-SNAPSHOTartifacts of the same version, while being built from different sources.To avoid that and make things safer, an administrator could:
.m2repositories according to the number of executors configured on an agent - for example,$HOME/0/.m2,$HOME/1/.m2, and$HOME/2./.m2if there are 3 executors;EXECUTOR_NUMBERenvironment variable in your build scripts:This will make the builds more isolated from each other, with a consequence of using three times more disk space on each agent.
However, the safest and simplest option is still to have more agents with one executor per each.