Nadarian Nadarian - 25 days ago 12
Groovy Question

Jenkins build matrix with unique parameter per configuration

I installed the Matrix Groovy Execution Strategy Plugin and I face an issue where for each of these builds I have to provide a unique parameter like bundle id or hockeyapp id. The plugin doesn't let me inject those parameters from inside the groovy script because it compares the combinations with the result values f.e.

Combinations:

{axis1:"a", axis2:"z"}


Result

{axis1:"a", axis2:"z", bundleId:"com.foo.bar"}


I don't like the idea of adding all the bundleIDs and hockeyappIDs as the dimensions because it produces a really huge matrix and any change in the parameters would produce great amount of changes needed in the script.

How can I add a unique parameter for each of the build configuration from the matrix?

Answer

What you probably want is the EnvInject plugin. Amongst other things this allows you to set environment variables in groovy script.

The current axes (axises) are available to this script as environment variables already

So add the plugin and this will give you a Inject environment variables to the build process under Build Environment

Under Evaluated Groovy script use a variant of this script

if(AXIS_A == "a")
    return  [COMPUTE_VAR: "123456"]
else
    return  [COMPUTE_VAR: "abcdefg"]

Assuming your axis is called AXIS_A

The method wants a map returned so it is possible to add multiple environment variables

From the help in Jenkins

Evaluate a Groovy script and inject a map result.

The groovy script must return a map Java object.

You can access parameters and other environment variables through variables in the Groovy script.

Comments