diff --git a/src/main/java/ca/silvermaplesolutions/jenkins/plugins/daxis/DynamicAxis.java b/src/main/java/ca/silvermaplesolutions/jenkins/plugins/daxis/DynamicAxis.java index c2ab686..869a601 100644 --- a/src/main/java/ca/silvermaplesolutions/jenkins/plugins/daxis/DynamicAxis.java +++ b/src/main/java/ca/silvermaplesolutions/jenkins/plugins/daxis/DynamicAxis.java @@ -9,13 +9,19 @@ import hudson.matrix.AxisDescriptor; import hudson.matrix.MatrixBuild; import hudson.model.TaskListener; +import hudson.slaves.EnvironmentVariablesNodeProperty; +import hudson.slaves.NodeProperty; import hudson.util.FormValidation; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Logger; import java.util.regex.Pattern; +import jenkins.model.Jenkins; import net.sf.json.JSONObject; import org.kohsuke.stapler.DataBoundConstructor; @@ -51,6 +57,7 @@ public DynamicAxis( String name, String varName ) { super( name, varName ); this.varName = varName; + axisValues.addAll(expandVariableIfPresent(getGlobalProperties())); } /** @@ -119,14 +126,7 @@ private void checkForDefaultValues() { // attempt to get the current environment variables final @Nonnull EnvVars vars = context.getBuild().getEnvironment( TaskListener.NULL ); - - // only spaces are supported as separators, as per the original axis value definition - String varValue = vars.get( varName ); - if( varValue != null ) - { - LOGGER.log( Level.FINE, "Variable value is ''{0}''", varValue); - newAxisValues.addAll(Arrays.asList(Util.tokenize(varValue))); - } + newAxisValues.addAll(expandVariableIfPresent(vars)); } catch( Exception e ) { @@ -147,6 +147,31 @@ private void checkForDefaultValues() return newAxisValues; } + private List expandVariableIfPresent( Map vars ) + { + String varValue = vars.get( varName ); + if( varValue != null ) + { + LOGGER.log( Level.FINE, "Variable value is ''{0}''", varValue); + // only spaces are supported as separators, as per the original axis value definition + return Arrays.asList(Util.tokenize(varValue)); + } + return Collections.emptyList(); + } + + private static Map getGlobalProperties() + { + Map globalProperties = new HashMap(); + for( NodeProperty nodeProperty : Jenkins.getInstance().getGlobalNodeProperties() ) + { + if( nodeProperty instanceof EnvironmentVariablesNodeProperty ) + { + globalProperties.putAll(((EnvironmentVariablesNodeProperty) nodeProperty).getEnvVars()); + } + } + return globalProperties; + } + /** * Descriptor for this plugin. */ @@ -198,9 +223,13 @@ public FormValidation doCheckValueString( @QueryParameter return FormValidation.warning( Messages.configPortableName() ); } - // see if it exists in the system; if not we cannot tell if it is valid or not + // see if it exists in the system or global variables; if not we cannot tell if it is valid or not String content = System.getenv( value ); if( content == null ) + { + content = getGlobalProperties().get( value ); + } + if( content == null ) { return FormValidation.warning( Messages.configBuildVariable() ); }