Shizzle
Shizzle

Reputation: 1001

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")])
                }
            }
        }
    }
}

Upvotes: 2

Views: 3484

Answers (1)

ilya
ilya

Reputation: 106

  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)

Upvotes: 1

Related Questions