Skip to content
Permalink
Browse files
[FIXED JENKINS-11577]
Traditionally, matrix axis values are only exposed as "build variables", and it was up to individual build steps and others to treat them equally like environment variables.

However, in practice, this distinction between environment variables vs build variables didn't serve any useful purposes, and the down side (of some plugins only expanding env vars in the ${VAR} notation and not build variables) was probably bigger than whatever benefit this distinction was supposed to bring.

In this fix, we are exposing matrix axis values also as environment variables. This will make them recognizable from plugins that only expand environment variables, such as parameterized trigger plugins as indicated in the original bug report.

This was motivated by pull request #701 but fix was made differently.
  • Loading branch information
kohsuke committed Feb 16, 2013
1 parent b225178 commit a6dddf2917c1d9ae819f86947a7ccffa2a04d728
Showing with 23 additions and 1 deletion.
  1. +3 −0 changelog.html
  2. +20 −1 core/src/main/java/hudson/matrix/MatrixConfiguration.java
@@ -83,6 +83,9 @@
<li class=bug>
Missing build title in /rssAll when build has no test result.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-16770">issue 16770</a>)
<li class=bug>
Changed the way matrix axis values are exposed as env variables
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-11577">issue 11577</a>)
<li class=rfe>
JNLP slave installers can now work transparently with secured Jenkins.
(SECURITY-54 / despite the ticket marker, this is not a security vulnerability)
@@ -23,11 +23,14 @@
*/
package hudson.matrix;

import hudson.EnvVars;
import hudson.Util;
import hudson.model.Action;
import hudson.model.Executor;
import hudson.model.InvisibleAction;
import hudson.model.Node;
import hudson.model.Queue.QueueAction;
import hudson.model.TaskListener;
import hudson.util.AlternativeUiTextProvider;
import hudson.util.DescribableList;
import hudson.model.AbstractBuild;
@@ -85,7 +88,23 @@ public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOExcep
// directory name is not a name for us --- it's taken from the combination name
super.onLoad(parent, combination.toString());
}


@Override
public EnvVars getEnvironment(Node node, TaskListener listener) throws IOException, InterruptedException {
EnvVars env = super.getEnvironment(node, listener);

AxisList axes = getParent().getAxes();
for (Map.Entry<String,String> e : getCombination().entrySet()) {
Axis a = axes.find(e.getKey());
if (a!=null)
a.addBuildVariable(e.getValue(),env); // TODO: hijacking addBuildVariable but perhaps we need addEnvVar?
else
env.put(e.getKey(), e.getValue());
}

return env;
}

@Override
protected void updateTransientActions(){
// This method is exactly the same as in {@link #AbstractProject}.

0 comments on commit a6dddf2

Please sign in to comment.