如何使用File参数作为参数触发下游jenkins作业? [英] How to trigger downstream jenkins job with File parameter as parameter?

查看:279
本文介绍了如何使用File参数作为参数触发下游jenkins作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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:

文件参数帮助如下:

已提交文件的名称在环境变量中可用,该环境变量的名称与文件位置相同.例如,如果将文件位置设置为 abc.zip [UPLOADED_FILE],则然后 $ {abc.zip} [$ {UPLOADED_FILE}] 将为您提供从浏览器传递的原始文件名(例如my.zip.)该名称将不包括目录名部分.

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.]

不幸的是,这在多个方面都是错误的(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:

POSIX.1-2008的Shell and Utilities卷中的实用程序使用的环境变量名称仅由大写字母,数字和('_') [...]

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 ( '_' ) [...]

另请参见 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 ParameterFile Location, use e.g. just UPLOADED_FILE
  • <Your upstream project> → ConfigureAdd post-build actionTrigger parameterized build on other projectsAdd parametersPredefined parametersParameters:

KEY =值对,每行一对(Java属性文件格式). [...]

当前的构建参数和/或环境变量可以以下形式使用:$ {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作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆