Reputation: 154
I have two jobs which are pipelined, I want to send the BUILD_NUMBER
info of upstream job to downstream.
The main point is we shouldn't trigger the downstream project. Triggering of downstream project should be manual.
Whenever I trigger the downstream job it need to get the latest BUILD_NUMBER
of the upstream.
How can I do this?
Upvotes: 1
Views: 986
Reputation: 733
Use environment inject plugin in the second job
As mentioned by @VnoC in the first job write the buildnumber in the properties file like below
echo "last_build_number = ${BUILD_NUMBER}"> ../Common.properties
Mention in the inject enviornement variable the same property file path for the secod job (Path is repective to the active workspace so keeping it in a common location)
Now is the second job you can access the variable like $last_build_number
Upvotes: 2
Reputation: 1323203
You could set an environment variable, which will then be read by the next job with WithEnv(${last_build_number}) {...}
.
That is not ideal since this is listed as an anti-pattern in Top 10 Best Practices for Jenkins Pipeline Plugin
While you can edit some settings in the env global variable, you should use the
withEnv
syntax instead.Why? because the env variable is global, changing it directly is discouraged as it changes the environment globally, so the
withEnv
syntax is recommended.
Still, in your case, that could be an acceptable workaround.
environment {
last_build_number = ${BUILD_NUMBER}
}
I thought first to write it in a file, but the feature of reading parameters from a file is still pending (JENKINS-27413
).
Upvotes: 0