Reputation: 233
I have two pipeline jobs.
Parent job: This job contains Gerrit trigger and builds on every patch-set created. After building of this job I can see the Gerrit environment variables into the build environment variable section.
Child job: which runs only if the gerrit_branch is not equal to master.
I want to pass all the gerrit environment variables to this job like the parent job.
Is there any way to pass all the env variable to the child job.
Upvotes: 3
Views: 3335
Reputation: 3402
I have taken two pipeline jobs: Pipeline1 (parent job) and pipelineB (child job)
Pipeline1: I am doing SCM checkout from github where Jenkinsfile is present and in Jenkinsfile, I have called pipelineB (child job) where I am passing the parent job environment variable (GIT_BRANCH).
Jenkinsfile of Pipeline1
pipeline {
agent any
stages
{
stage ('Build JobB')
{
steps {
sh 'env'
build job: 'pipelineB', parameters: [string(name: 'GITHUB_BRANCH', value: "${env.GIT_BRANCH}")]
}
}
}
}
GIT_BRANCH is environment variable here. (https://plugins.jenkins.io/git/#environment-variables)
pipelineB: I have used the option This build is parameterized to capture the value of environment value being passed by parent job i.e. Pipeline1. Then, used the variable in pipeline script.
Please try it out.
Upvotes: 1