简体   繁体   English

Jenkins触发参数插件-文件参数

[英]Jenkins trigger parameter plugin - file parameters

I have Project A and downstream Project B, which takes in a file parameter. 我有项目A和下游项目B,它们需要一个文件参数。 Project B is triggered (from Parameterized Trigger Plugin ) by A when A is completed. 当A完成时,项目B由A触发(来自Parameterized Trigger Plugin )。 Is there a way that I can predefine the file parameter (eg file properties file) so when project A->B, B will be able to obtain the file without needing a manual selection? 有没有一种方法可以预定义文件参数(例如文件属性文件),以便当项目A-> B时,B无需手动选择就可以获取文件?

You can use the Multijob plugin for this. 您可以为此使用Multijob插件

A simple implementation for your example would be to have a third (multijob) project which then has two multijob phases with you one project in each one. 您的示例的一个简单实现是拥有第三个(多任务)项目,该项目具有两个多任务阶段,每个阶段都有一个项目。 You can specify the behaviour on the exit code for each phase and use parameters with the 'advanced' button on the configuration page 您可以在每个阶段的退出代码上指定行为,并通过配置页面上的“高级”按钮使用参数


EDIT The multijob plugin does not support File parameters (such as a file passed in from the browser), which is a shame 编辑multijob插件不支持File参数(例如从浏览器传入的文件),这很可惜

However you can fake it by 但是你可以通过伪造

PROJECT A (__upstream) 项目A(__上游)

where params.txt is the file parameter 其中params.txt是文件参数

上游工作

PROJECT B (__downstream) 项目B(__下游)

where params.txt is the file parameter 其中params.txt是文件参数

下游工作

Results when triggered from A 从A触发时的结果

Started by upstream project "__upstream" build number 8
originally caused by:
 Started by user anonymous
[EnvInject] - Loading node environment variables.
Building on master in workspace /var/lib/jenkins/workspace/__downstream
[__downstream] $ /bin/sh -xe /tmp/hudson4094819031189787422.sh
+ touch params.txt
[EnvInject] - Injecting environment variables from a build step.
[EnvInject] - Injecting as environment variables the properties file path 'params.txt'
[EnvInject] - Variables injected successfully.
[__downstream] $ /bin/sh -xe /tmp/hudson1756581135746292166.sh
+ cat params.txt
+ env
+ grep TEST
+ sort
TEST1=abc
TEST3=xyz
+ rm params.txt
Finished: SUCCESS

Results when triggered directly 直接触发时的结果

Started by user anonymous
[EnvInject] - Loading node environment variables.
Building on master in workspace /var/lib/jenkins/workspace/__downstream
Copying file to params.txt
[__downstream] $ /bin/sh -xe /tmp/hudson5504289990867483427.sh
+ touch params.txt
[EnvInject] - Injecting environment variables from a build step.
[EnvInject] - Injecting as environment variables the properties file path 'params.txt'
[EnvInject] - Variables injected successfully.
[__downstream] $ /bin/sh -xe /tmp/hudson8534892071758952425.sh
+ cat params.txt
TEST1=abc
TEST3=xyz

+ env
+ sort
+ grep TEST
TEST1=abc
TEST3=xyz
+ rm params.txt
Finished: SUCCESS

You have to touch the file in the downstream, or else the EnvInject plugin chokes on no file and remember to remove the file (or rename) so the next run doesn't reuse the values 您必须触摸下游的文件,否则EnvInject插件会在没有文件的情况下阻塞,并记住删除该文件(或重命名),以便下次运行时不会重复使用这些值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM