Hey all,
I had this interesting thing to do :-
Requirement: To pass a parameter from one Jenkins job to another(downstream job) & to display this parameter as part of the second job report.
Solution:After reading few threads on the solution, I inferred that the plugin that would do the job for me was this “Parameterized Trigger Plugin”. –> https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin
Once this plugin is installed , go to Job 1(upstream job) > Post-Build Actions > Select ”Trigger parameterized build on other projects”
The option I chose is given below :-
I had to send the ‘Build_Number’ of this job to the next. So assigned to a variable ‘Temp’.
The complete list of Jenkins Environment Variables are seen here.
In the Downstream Job: To access this parameter use $Temp where you need it. In my case I used in the Editable Email Notification.
There are many other ways of assigning parameters from one job to another using this plugin. You can explore them. This one worked for me like a charm so thought I’d share my 2 cents :).
Regards,
VJ
You saved me 1-2 hours. Thanx for the clear description and sharing
LikeLike
The plugin doesn’t work anymore (see the long list of open issues). Any other solution?
LikeLike
Hans,
This plugin does still work.I’ve used it just recently.
LikeLike
In the newest (since 1.651.2) versions of Jenkins you must define your passed parameter (Temp in the example) as a parameterized build parameter in the downstream job before the parameter will be passed.
LikeLike
Thanks Randy..For the update.. I am unaware of these changes… Will look into it..
LikeLike
Hi Randy,
Thank you so much. This is working for me.. Banging my head from 2 hours. After upgrading my jenkins to 1.651.3, enviornment injection suddenly stopped working. Yes we have to define the same parameters in both parent and child jobs. Unfortunately there is no clear documentation on this
Much appreciated your help.
LikeLiked by 1 person
This works for post build, but not for promoted builds.
I worked around it as recommended by someone on stackoverflow by creating a parameters file and loading it into the promote build job.
Also, using parameters on the promoted build doesn’t work as it escapes everything and doesn’t translate vars into values before the escaping.
LikeLike
Hi,
Could you describe how did you load a parameters file into your promoted build?
I always get error:
> [parameterized-trigger] Properties file my.properties did not exist.
on attempt to start a promoted build. It seems that file that is created during build run doesn’t not exist anymore when promoted build starts.
LikeLike
I think I figured it out. In order to pass any of custom build environment parameters to a promotion build, those params should be saved to a file during build and archived into build artifacts. So the promotion build can use “Copy artifacts” plugin to get the artifact archive from upstream build. Using “Inject environmental variables” plugin the params from the file get injected into promotion build.
LikeLike
can you please tell me breafly how to access parameters in downstream project
LikeLike
Suppose the parameter is ‘foo’ in the first Jenkins job, then in the downstream job you can access this by giving ‘$foo’ .
LikeLike
Can you asist on this scenario?
Later if i do any another downstream job then how do i access first jobs foo into third job ?
first job (foo) > downstream job (access thru $foo) > down stream job (here i want to access foo of first job)
LikeLike
What if the passed parameter is a variable created in the script and not a Jenkins environment variable?
This doesn’t seem to work in that case.
LikeLike
Same here as Assaf. If I put in Predefined parameters:
BuildName=${RELEASE}
Then ${RELEASE} is passed to the next project. I want to pass the value defined in my script. That is not happening. Hardcoding does work:
BuildName=BestBuildEver
works fine. BestBuildEver is passed as the value of BuildName in the next project.
LikeLike
Hi Assaf,
Sorry for the late reply, you can pass any variable from one job to another, not just Jenkins Environment Variables. I will explain this in a detailed blog soon.
LikeLike
I found a simple explanation of how to make that work:
LikeLiked by 1 person
How to pass parameters from a pipeline job to a maven job?
LikeLike
Thanks,
but how can I get these parameters inside downstreamed job if I want to use them in “This build is parametrized” chapter?
Like ${variable} or $variable, or {variable}?
LikeLike
what if there are multiple parameters from upstream job to downstream job
like
key1=val1
key2=va12
key3=val3 and so on
How to accept accept this in downstream job.?
I used Multi-line String parameter and gave key1,key2,key3 but it didn’t work
LikeLike
This is possible. Precede $ with the variable sent from the upstream to access it downstream.
LikeLike