使用Jenkins和多配置复制工件时要聪明 [英] Being clever when copying artifacts with Jenkins and multi-configurations

查看:92
本文介绍了使用Jenkins和多配置复制工件时要聪明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一组(虚拟的)项目:FOO和BAR.这两个项目都有某种多配置选项.

Suppose that I have a (fictional) set of projects: FOO and BAR. Both of these projects have some sort of multi-configuration option.

FOO在轴X上具有一个矩阵,该矩阵采用{ x1, ..., xn }中的值(因此有n个FOO版本). BAR在轴Y上具有一个矩阵,该矩阵采用{ y1, ..., ym }中的值(因此有m个构建的BAR).

FOO has a matrix on axis X which takes values in { x1, ..., xn } (so there are n builds of FOO). BAR has a matrix on axis Y which takes values in { y1, ..., ym } (so there are m builds of BAR).

但是,BAR需要从FOO复制一些工件.事实证明,Y是一个比n更严格的分区.例如,X可能使用值{ WINDOWS, LINUX },而Y可能是{ WINDOWS_XP, WINDOWS_7, DEBIAN_TESTING, FEDORA }或其他任何值.

However, BAR needs to copy some artifacts from FOO. It turns out that Y is a strictly finer partition than n. For example, X might take the values { WINDOWS, LINUX } and Y might be { WINDOWS_XP, WINDOWS_7, DEBIAN_TESTING, FEDORA } or whatever.

是否有可能使BAR进行某种表查找,以计算出复制工件时所需的FOO的配置?我可以很容易地编写一个shell脚本来吐出映射,但是当詹金斯(Jenkins)确定需要复制的内容时,我不知道如何调用它.

Is it possible to get BAR to do some sort of table lookup to work out what configuration of FOO it needs when it copies artifacts across? I can easily write a shell script to spit out the mapping, but I can't work out how to invoke it when Jenkins is working out what it needs to copy.

目前,一个有问题的解决方案是在FOO上有两个轴,在X上有两个轴,而在Y上有一个轴,然后过滤掉没有意义的组合.但是,最终的组合滤波器非常荒谬,矩阵非常稀疏. uck.

At the moment, a hacky solution is to have two axes on FOO, on for X and one for Y, and then filter out combinations that don't make sense. But the resulting combination filter is ridiculous and the matrix is very sparse. Yuck.

我不喜欢的解决方案是在Y上参数化FOO:这将浪费大量的编译时间.而且,更糟糕的是,生成的伪像相当大,因此,即使您进行了某种缓存,您仍然必须保持不必要的副本四处浮动.

A solution that I don't like is to parametrise FOO on Y instead: this would be a huge waste of compile time. And, worse, the generated artefacts are pretty big, so even if you did some sort of caching, you'd still have to keep unnecessary copies floating around.

推荐答案

不能说我完全理解矩阵的复杂性,但是我想我可以为您解决实际问题

Can't say I fully understand the intricacies if your matrices, but I think I can help you with your actual question

"I can easily write a shell script to spit out the mapping, but I can't work out how to invoke it when Jenkins is working out what it needs to copy"

归档工件从另一个项目复制工件,生成后的操作可以采用Java样式的通配符,例如module/dist/**/*.zip以及环境变量/参数,例如${PARAM}以获得列表或工件.您可以使用逗号,添加更多工件.

The Archive the artifacts and Copy artifacts from another project post-build actions can take java style wildcards, like module/dist/**/*.zip as well as environment variables/parameters, like ${PARAM} for the list or artifacts. You can use commas , to add more artifacts.

从另一个项目复制工件的页面帮助说明了如何复制特定矩阵配置的工件:To copy from a particular configuration, enter JOBNAME/AXIS=VALUE,这是针对Project Name属性的.该project name属性也可以包含${PARAM}

The on-page help for Copy artifacts from another project states how to copy artifacts of a specific matrix configuration: To copy from a particular configuration, enter JOBNAME/AXIS=VALUE, this is for the Project Name attribute. That project name attribute can also contain params as ${PARAM}

因此,在您的 BAR 工作中,有一个 Copy Artifacts 构建步骤,其中Project NameFOO/X=${mymapping}.这样做是:每次运行BAR的配置时,它只会从配置为X=${mymapping}FOO复制工件.

So, in your BAR job, have a Copy Artifacts build step, with Project Name being FOO/X=${mymapping}. What this will do is: every time a configuration of BAR is run, it will copy artifacts only from FOO with configuration of X=${mymapping}.

现在,每次运行BAR时,都需要动态设置${mymapping}的值.像这样的简单脚本可以达到目的:

Now you need to set the value of ${mymapping} dynamically every time BAR is run. A simple script like this may do the trick:

[[ ${Y:0:7} == "WINDOWS" ]] && mymapping=WINDOWS || mymapping=LINUX

最后,您需要使用 EnvInject 插件,以使该变量可用于其余的构建步骤,包括 Copy Artifacts 步骤.

Finally, you need to use EnvInject plugin to make this variable available to the rest of the build steps, including the Copy Artifacts step.

因此,每次BAR配置运行时,它都会查看其自己的配置轴Y,如果该轴以WINDOWS开头,则会将${mymapping}设置为WINDOWS,否则进行设置到LINUX.然后,此${mymapping}可用于其余的构建步骤.当执行Copy Artifacts构建步骤时,它将仅从FOO匹配${mymapping}轴(即WINDOWSLINUX)的FOO复制工件.

So, every time BAR configuration runs, it will look at its own configuration axis Y, and if that axis starts with WINDOWS, it will set the ${mymapping} to WINDOWS, else set it to LINUX. This ${mymapping} is then made available to the rest of the build steps. When Copy Artifacts build step is executed, it will only copy artifacts from FOO where the X axis matches ${mymapping} (i.e. either WINDOWS or LINUX).

  • 安装 EnvInject 插件.
  • BAR 作业配置中,勾选Prepare an environment for the run(EnvInject插件的一部分).
  • 确保选中两个用于保留现有变量的复选框.
  • Script Content中复制您的脚本:
    [[ ${Y:0:7} == "WINDOWS" ]] && mymapping=WINDOWS || mymapping=LINUX
  • Build 步骤下,配置 Copy Artifacts 构建步骤.
  • 项目名称参数设置为FOO/X=${mymapping}
  • 像往常一样配置其余部分.
  • Install EnvInject plugin.
  • In BAR job configuration, tick Prepare an environment for the run (part of EnvInject plugin).
  • Make sure both checkboxes for keeping existing variables are checked.
  • In Script Content copy your script:
    [[ ${Y:0:7} == "WINDOWS" ]] && mymapping=WINDOWS || mymapping=LINUX
  • Under Build steps, configure Copy Artifacts build step.
  • Set Project name parameter to FOO/X=${mymapping}
  • Configure the rest as usual.

这篇关于使用Jenkins和多配置复制工件时要聪明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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