Reputation: 1935
I have a pipeline that runs a Windows container and can run in different nodes. Each node has a different amount of threads. Because of Hiper-V isolation in Windows, I only get two cores on each container by default, although the host machine has more than two. My idea is to configure each Jenkins node to have an environmental variable telling how many threads you can use:
Then, I can use the env.CORES
variable to set the --cpus
flags in the docker:
pipeline {
agent {
docker {
image 'mcr.microsoft.com/dotnet/framework/runtime:4.8'
args '--pull always'
label 'windows-build'
}
}
stages {
stage('Prepare') {
steps {
echo 'Node name: ' + env.NODE_NAME
echo 'CORES: ' + env.CORES
}
}
}
}
However, at the time of running the docker, it fails as the env.CORES
variable is null
.
Any idea on how to do so? I have thought and given some tries to read the host machine environmental variable NUMBER_OF_PROCESSORS
(link) but apparently, the problem is that at that time the Jenkins node is not yet assigned....
Upvotes: 0
Views: 26