Switching a matrix job between two matrix sets with a parameter?

432 views
Skip to first unread message

Benjamin Lau

unread,
Aug 30, 2012, 12:22:39 PM8/30/12
to Jenkins Users
Hello,

Say I've got a matrix job with 2x2x15 jobs. For some builds I would
like to have this run as a 2x1x1 matrix instead. Is there an easy way
to change the job's combination filter via a parameter or something
like that? I tried passing in the combination filter as a build
parameter, but I don't think it can handle parsing a parameter
variable definition.

Baring that... is there a way I could programatically update the job
from another job?

Thanks in advance,

Ben

cjo

unread,
Aug 31, 2012, 7:42:19 AM8/31/12
to jenkins...@googlegroups.com
Use the parameterized trigger plugin, as that has a parameter to pass in matrix subset to build, using that combination rather than the defined one in the project.

Benjamin Lau

unread,
Aug 31, 2012, 10:11:00 AM8/31/12
to jenkins...@googlegroups.com
Haha... I'm currently running 2.13... so close. ;-)

I'll update tonight since the day's builds are just starting. Jenkins
was in need of a maintenance cycle anyway.

Thanks!

Ben

Benjamin Lau

unread,
Aug 31, 2012, 11:35:50 AM8/31/12
to jenkins...@googlegroups.com
I was able to update sooner. So this uses a groovy statement to deal
with the combination... how exactly would this work? And how would I
make use of a parameter on the build doing the triggering to decide
which of two combinations to use?

Do you have an example I could look at?

Ben

cjo

unread,
Aug 31, 2012, 1:27:54 PM8/31/12
to jenkins...@googlegroups.com
The groovy filter expression is the same as you would specify in Combination filter of the matrix job 
and is applied on top of the combination filteer already set for the matrix job.

So as you have 3 axis with multiple items.
e.g.

TARGET = target_a, target_b
SIGNING = release, development
PRODUCT = Product_1, ... Product_15

The combination filter to build just Product_5 for all targets and signing would be
(PRODUCT=="Product_5")

or to build just product 5 for development
(PRODUCT=="Product_5" && SIGNING=="development")

The combination filter in the matrix job should be set so that only the valid configurations can be built,
as when it is triggered from the upstream job using the Matrix Subset parameter it will be combined together.
If all of the combinations of the Axis are valid you do not need to set the combination filter.

Now if you start the job with a Matrix subset parameter you can define which axis combinations should be built,

So if the combination filter on the matrix job is set to build just Product_5 and Product_10 for all targets and signings
(PRODUCT=="Product_5" || PRODUCT=="Product_10") - this would produce 8 combinations.

To limit this just Product_5 and development, you would trigger the build with the this combination 
(PRODUCT=="Product_5" && SIGNING=="development")

Which would produce 2 builds rather than the default 8 builds.


So if your 2x2x15 is the full set with no combination filter, then you can just run that as normal, 
and if you want the smaller 2x2x1 set you would start that with a matrix subset parameter.


If you dynamically want to set this from an upstream job, I would suggest having the following groovy expression 

(${ALL} || <restricted subset expression>)

which means that you can have env property injected into the build as for ALL="true" to build all of the matrix and set it to false to build the subset.
I tested this by just using a boolean parameter on the upstream build.

Note: you can't just export the Value in a shell, as you need to add it to the Jenkins build Environment. (use the EnvInject plugin if needed.)

Of course the expressions can be made as complex as you like depending on your needs.
e.g. selecting one of three subsets could be done as 
(${SUBSET}=="Set1" && <subset1 expression>) || (${SUBSET}=="Set2" && <subset2 expression>) || (${SUBSET}=="Set3" && <subset3 expression>)

Chris

Benjamin Lau

unread,
Sep 8, 2012, 2:18:03 AM9/8/12
to jenkins...@googlegroups.com
Thanks for the help Chris! This worked perfectly (used the multiple
subset example from then end of your reply). Just one minor note (if
anyone comes across this and wants to do it...

This form doesn't work... I was getting an error when I used this in
my initial attempt:
(${SUBSET}=="Set1" && <subset1 expression>) || (${SUBSET}=="Set2" &&
<subset2 expression>) || (${SUBSET}=="Set3" && <subset3 expression>)

But by changing it to (quoting the ${SUBSET} expressions):
("${SUBSET}"=="Set1" && <subset1 expression>) || ("${SUBSET}"=="Set2"
&& <subset2 expression>) || ("${SUBSET}"=="Set3" && <subset3
expression>)

It worked like a charm.

Thanks again for the assistance!

Ben
Reply all
Reply to author
Forward
0 new messages