最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

windows - Jenkins pipeline using docker set the --cpus flag from an environmental variable - Stack Overflow

programmeradmin0浏览0评论

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/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....

发布评论

评论列表(0)

  1. 暂无评论