This pipeline can run in several windows nodes that have different number of threads each. For some reason, the docker only gets 2 out of the N cores as I explain here. So I thought that if I could have an env variable in the node defining the number of threads, I could change the pipeline to
I don’t think a declarative pipeline can handle that. Here’s an example using a scripted pipeline:
By the way, it will be easier if by ‘core’ you mean the CPU count of the node – you can retrive that number by a shell cmd.
node("10.33.105.107"){
def computer = Jenkins.instance.getComputer("10.33.105.107")
def all = computer.getAllExecutors().size().toString()
docker.image('ubuntu').inside("--cpus ${all}") {
stage('Test') {
sh 'whoami'
}
}
}
I don’t think that using the number of executors of the node is the right approach. It says nothing about the number of CPUs on that node.
I have agents that have 120 CPUs and a single executor configured and others that have just 4 CPUs but 15 executors. It all depends on what you do on the machine
You might consider using --cpu-shares instead which is not an absolute value but a weighted value (check the docker docs)