问题
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