0

pipeline { agent { label 'linux' }

stages{
    stage("verify1"){
        steps {
            script {
                build(job: "verfiy1", parameters: [string(name: 'verfiy1', value: "${params.verfiy1}")])
            }
        }
    }
    
    stage("verify2"){
        steps {
            script {
                build(job: "verfiy2", parameters: [string(name: 'verfiy2', value: "${params.verfiy2}")])
            }
        }
    }
    
    stage("verify3"){
        steps {
            script {
                build(job: "verify3", parameters: [string(name: 'verify3', value: "${params.verify3}")])
            }
        }
    }
}

}

=================================================================

Hello

can anyone help me, right now from the above pipeline i am able to build 3 jobs sucessfull but the problem is every single job is executing on new ec2 slave instance instead of the instance where the job has started. I am expecting the output as once the above pipeline starts all the builds in the pipeline must execute on the same node (ec2 instance).

Thanks in advance

skkc
  • 13
  • 4

1 Answers1

0

You can pass the upstream job's agent node to the downstream job.

  1. Add one more job parameter to accept node
  2. Pass upstream job's agent node via env.NODE_NAME when call build job step
// verify 1 job

pipeline {
   agent { label "${params.agentNode}" }
   parameters {
      string(name: "agentNode", 
             defaultValue="<give default value in case run it directly>" )
   }
}

// upstream job

build(job: "verify1", parameters: [
    string(name: 'agentNode', value: "${env.NODE_NAME}"),
    string(name: 'verify3', value: "${params.verify3}")
])
yong
  • 13,357
  • 1
  • 16
  • 27
  • Hi there, Thanks for the revert. I have tried the above way and declared label "${params.agentNode}" in the build jobs pipelines verfiy1, 2 & 3, where it assigns env.NODE_NAME value from the main job to downstream build jobs verify 1,2,3 using the parameters. This way it kept on looking for the node which it couldn't find. Thanks – skkc Oct 27 '22 at 15:33
  • I guess the agent label 'linux' is a group machine, the upstream job pick one from the group to build itself, but every machine in the group is not labeled, thus the downsteam job can not find the machine by label: env.NODE_NAME – yong Oct 28 '22 at 00:36