I have a Jenkins Job which accepts a File as a parameter and using same file I would like to trigger downstream project. How do I do it ? It seems jenkins doesn't support passing files as parameter to downstream project. I am using 'Trigger/Call builds on other projects' to trigger a downstream project.
Use the Parameterized Trigger Plugin but be aware of the following:
The File Parameter help reads:
The name of the submitted file is available in the environment variable whose name is the same as file location. For example, if you set the file location to be
abc.zip[UPLOADED_FILE], then${abc.zip}[${UPLOADED_FILE}] would give you the original file name passed from the browser (such as my.zip.)The name will not include the directory name portion.
[Strikethroughs and additions by me.]
Unfortunately this is wrong in more than one respect (with Jenkins v1.609.1):
Why is each of these bad?
Well, the latter is the opposite to the inline help and both might lead to unexpected results (and it did in my case), since '.' and '/' are not standardized characters in variable names according to IEEE Std 1003.1, 2013 Edition:
Environment variable names used by the utilities in the Shell and Utilities volume of POSIX.1-2008 consist solely of uppercase letters, digits, and the ( '_' ) [...]
See also Robert Gamble's answer to Allowed characters in linux environment variable names.
So, the answer is:
<Your upstream project> → Configure → Add post-build action → Trigger parameterized build on other projects
→ Add parameters → Predefined parameters → Parameters:
KEY=value pairs, one per line (Java properties file format). [...]
Current build parameters and/or environment variables can be used in form: ${PARAM} or $PARAM.
Long story short. This passes the file's absolute name to your downstream project:
ENV_VAR_IN_DOWNSTREAM_PROJECT=${WORKSPACE}/${UPLOADED_FILE}
UPDATE
I created a respective issue: [JENKINS-28996] Environment variable name created from File Parameter → File Location contains the "directory name portion" though stated differently in its inline help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With