2

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!

Namrata Shilpi
  • 139
  • 1
  • 15
  • https://stackoverflow.com/a/52807254/7983309 – ben5556 Dec 04 '18 at 03:24
  • 1
    You specified agent label for stage, not for the JOB A. I think JOB A will find an available agent from the `Restrict where this project can be run` you configured in JOB A's configuration. Thinking about JOB A will be executed on which agent when you manually build JOB A. Trigger JOB A in pipeline stage just make the trigger automatically. But the JOB A behavior should same as trigger manually. – yong Dec 05 '18 at 10:57

1 Answers1

3

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]
        }
        }
    }
}
Namrata Shilpi
  • 139
  • 1
  • 15