'How to import env variables in child jenkinsfile from parent jenkinsfile?
I have a monorepo setup where I am trying to dispatch service Jenkinsfile from root JenkinsFile The structure looks like this:
Monorepo
- Jenkinsfile (at root)
- services
- Jenkinsfile (services Jenkinsfile)
- Service A
- src/
- Service B
- src/
Service Jenkinsfile is triggered from root Jenkinsfile.
These env variables are working fine in root jenkinsfile but they are giving null values in service jenkinsfile.
stage('Echo env') {
echo "Branch_name=${env.BRANCH_NAME}, PR_Branch_change=${env.CHANGE_BRANCH}, PR_Key=${env.CHANGE_ID}, PR_Base=${env.CHANGE_TARGET}, Key=$CHANGE_ID, branch=$CHANGE_BRANCH, base=$CHANGE_TARGET"
} // Stage is same in both the jenkinsfile
In service jenkinsfile either gives error:
or Print Null values
Is there any way to import or reference the env variables from another (root) Jenkinsfile
Solution 1:[1]
Finally, I was able to get env variables values printed from parent jenkinsfile to child jenkinsfile
Here is the post I went through and somehow it helped me getting end result
Pass environment variables from parent job to child job Jenkins pipeline
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rajat jain |
