How to Pass downstream parameter ( e.g Current build parameter ) to downstream job of Jenkins. How to write Scripted pipeline for the same?

Viewed 300

enter image description here

I have attached a screenshot of the parameter I want to convert. I can not find the scripted pipeline syntax for aggregate downstream test results.

1 Answers

Let us pass below params to downstream jobs:-

def build_number_of_build="${BUILD_NUMBER}"
def job_name_of_build="${JOB_NAME}" 

pipeline {
    agent {
        label 'node_1'
    }

    stages {
        stage('trigger-downstream-job') {
        steps{
        build job: 'Downstream_Job', parameters: [[$class: 'StringParameterValue', name: 'job_name_of_build', value: job_name_of_build ], [$class: 'StringParameterValue', name: 'build_number_of_build', value: build_number_of_build ]], wait: false
        }
        }

    }
}

Now, how to retrieve it in Downstream_Job?

now you can call directly $job_name_of_build $build_number_of_build any where in Downstream_Job, provided the variable job_name_of_build, build_number_of_build are defined in the Downstream_Job, to that they can get value from upstream job.

Related