Reputation: 173
I have a jenkins job Job1 that sets a environment variable say CLIENT_CODE
. I would like to use this variable value in a different jenkins job Job2, and i like to fetch this variable data from the last successful build of Job1.
Setting the variable is done from a shell command in Job1. And Job2 also uses shell commands to fetch this variable value.
Please let me know an approach to do this.
Upvotes: 0
Views: 931
Reputation: 2076
build job: 'path/to/downstream/project/job2', parameters: [string(name: 'PARAM1', value: "${environment-variable-to-pass-from-job1}")
OR
withCredentials([usernamePassword(credentialsId: 'credentialID', usernameVariable: 'user', passwordVariable: 'password')]) {
CLIENT_CODE = sh (script: 'curl -s -u $user:$password https://job-url/job/jobName/${JOB_NUMBER}/consoleText | grep "CLIENT_CODE" | sed \'s/.*=//\'', returnStdout: true).trim()
}
OR
Upvotes: 1