问题描述
我有一个Jenkins Job,它接受File作为参数,并使用与我想触发下游项目相同的文件.我该怎么做 ?詹金斯似乎不支持将文件作为参数传递给下游项目.我正在使用在其他项目上触发/调用"来触发下游项目.
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:
文件参数帮助如下:
[我的删除线和附加内容.]
[Strikethroughs and additions by me.]
不幸的是,这在多个方面都是错误的(Jenkins v1.609.1):
- 成为环境变量名称的文件名称 abc.zip 不好.
- 如果文件位置字段中有目录名称部分,则 会包含在变量名称中.
- The file name abc.zip becoming an environment variable name is bad.
- If there is a directory name portion in the File Location field it is included in the variable's name.
为什么每一个都不好?
好吧,后者与内联帮助相反,并且两者都可能导致意外的结果(在我的情况下确实如此),因为'.根据 IEEE标准1003.1,2013年,变量名称中的和"和"/"不是标准化字符版本:
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:
另请参见 Robert Gamble对 Linux环境变量名称中允许的字符 的回答.
See also Robert Gamble's answer to Allowed characters in linux environment variable names.
所以,答案是:
- 在文件参数→中不使用路径或扩展名; 文件位置,例如只是 UPLOADED_FILE
-
<您的上游项目> → 配置→ 添加构建后操作→ 在其他项目上触发的参数化构建→ 添加参数→ 预定义参数→ 参数:
- Don't use a path or an extension in File Parameter → File Location, use e.g. just UPLOADED_FILE
<Your upstream project> → Configure → Add post-build action → Trigger parameterized build on other projects→ Add parameters → Predefined parameters → Parameters:
当前的构建参数和/或环境变量可以以下形式使用:$ {PARAM}或$ PARAM.
长话短说.这会将文件的绝对名称传递给您的下游项目:
Long story short. This passes the file's absolute name to your downstream project:
ENV_VAR_IN_DOWNSTREAM_PROJECT=${WORKSPACE}/${UPLOADED_FILE}
更新
我创建了一个相应的问题: [JENKINS-28996]环境变量名称通过文件参数→文件位置创建的文件包含目录名部分",尽管在其内联帮助中有所不同
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
这篇关于如何使用File参数作为参数触发下游jenkins作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!