简体   繁体   中英

Using the same node on all Downstream jobs in a Jenkins Pipeline

I've tried using the following Script, but all downstream jobs are running on different nodes.

Any idea how can I get a random node and run all downstream jobs on the same one?

 #!/usr/bin/env groovy pipeline { agent { label 'WindowsServer' } stages{ stage("Get Dev Branch"){ steps { script { build(job: "GetDevBranchStep", parameters: [string(name: 'DevBranchName', value: "${params.CloudDevBranch}")]) } } } stage("Get SA Branch"){ steps { script { build(job: "GetSABranchStep", parameters: [string(name: 'SABranchName', value: "${params.SABranch}")]) } } } stage("Compile Models and Copy To Network Folder"){ steps { script { build(job: "CompileNewModelsAndCopyToNetwork", parameters: [string(name: 'DevBranchName', value: "${params.CloudDevBranch}"), string(name: 'SABranchName', value: "${params.SABranch}"), string(name: 'GetSAStepJobName', value: "GetSABranchStep"), string(name: 'GetDevRepoJobName', value: "GetDevBranchStep"), string(name: 'NetworkFoderToCopyTo', value: "NetworkFolderAddress")]) } } } } } 

  1. provide a downstream job with ${NODE_NAME} as additional parameter
  2. in downstream job in agent section you can use:

    agent { label "${params.NODE_NAME}" }

(meanwhile did not found how to inject parameters of upstream job to the downstream without actually insert them one by one as input parameters)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM