Jenkins Pipeline, downstream job and Agent label

删除回忆录丶 提交于 2020-01-06 05:15:09

问题


I have a Jenkins Pipeline that executes Job A and Job B. I have 10 agents/nodes on which Job A is executed. If I specify Agent1, when I Build Pipeline, then Job A should execute on Agent1.

Issue: Pipeline is running on Agent1 and JobA is getting picked up on any random available agent.

Script:

pipeline { agent none stages { stage('JOB A') { agent { label "${machine}" } steps { build job: 'JOB A', parameters: [a,b,c,d,e,f] } } stage('JOB B') { agent { label 'xyz' } steps { build job: 'JOB B', parameters: [a,b,c,d,e,f,] } } } }

I'm using different label for every agent.

Can someone help me understand how and where the Pipeline and downstream jobs are running?

Thanks!


回答1:


As rightly pointed by @yong, I 'specified agent label for stage, not for the JOB A'.

So I declared a label parameter in JOB A and passed it downstream via the Pipeline. It's now correctly executing on the specified Agent.

pipeline {
agent { label 'master' }
stages {
    stage('JOB A') {
        steps {
            build job: 'JOB A', parameters: [a, [$class: 'LabelParameterValue', name: 'Agent', label: "${Agent}" ], b, c, d]
        }
        }
    stage('JOB B') {
        steps {
            build job: 'JOB B', parameters: [x,y,z]
        }
        }
    }
}


来源:https://stackoverflow.com/questions/53604983/jenkins-pipeline-downstream-job-and-agent-label

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!