Suppose that I have a (fictional) set of projects: FOO and BAR. Both of these projects have some sort of multi-configuration option.
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).
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.
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.
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.
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"
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.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 theProject Name
attribute. Thatproject name
attribute can also contain params as${PARAM}
So, in your BAR job, have a Copy Artifacts build step, with
Project Name
beingFOO/X=${mymapping}
. What this will do is: every time a configuration ofBAR
is run, it will copy artifacts only fromFOO
with configuration ofX=${mymapping}
.Now you need to set the value of
${mymapping}
dynamically every timeBAR
is run. A simple script like this may do the trick:Finally, you need to use EnvInject plugin to make this variable available to the rest of the build steps, including the Copy Artifacts step.
So, every time
BAR
configuration runs, it will look at its own configuration axisY
, and if that axis starts withWINDOWS
, it will set the${mymapping}
toWINDOWS
, else set it toLINUX
. This${mymapping}
is then made available to the rest of the build steps. WhenCopy Artifacts
build step is executed, it will only copy artifacts fromFOO
where theX
axis matches${mymapping}
(i.e. eitherWINDOWS
orLINUX
).Full Setup
Prepare an environment for the run
(part of EnvInject plugin).Script Content
copy your script:[[ ${Y:0:7} == "WINDOWS" ]] && mymapping=WINDOWS || mymapping=LINUX
FOO/X=${mymapping}