Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,6 +57,7 @@ public DynamicAxis( String name, String varName )
{
super( name, varName );
this.varName = varName;
axisValues.addAll(expandVariableIfPresent(getGlobalProperties()));
}

/**
Expand Down Expand Up @@ -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 )
{
Expand All @@ -147,6 +147,31 @@ private void checkForDefaultValues()
return newAxisValues;
}

private List<String> expandVariableIfPresent( Map<String, String> 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<String, String> getGlobalProperties()
{
Map<String, String> globalProperties = new HashMap<String, String>();
for( NodeProperty<?> nodeProperty : Jenkins.getInstance().getGlobalNodeProperties() )
{
if( nodeProperty instanceof EnvironmentVariablesNodeProperty )
{
globalProperties.putAll(((EnvironmentVariablesNodeProperty) nodeProperty).getEnvVars());
}
}
return globalProperties;
}

/**
* Descriptor for this plugin.
*/
Expand Down Expand Up @@ -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() );
}
Expand Down