Skip to content

Commit

Permalink
[FIXED JENKINS-19889] - Fixed handling of "Additional variables"
Browse files Browse the repository at this point in the history
Now the plugin exposes "exported variables" from tool's global configuration. I've also added a stub for future tests.

Resolves https://issues.jenkins-ci.org/browse/JENKINS-19889

Signed-off-by: Oleg Nenashev <nenashev@synopsys.com>
  • Loading branch information
oleg-nenashev committed Nov 12, 2013
1 parent d9431ca commit ed6e1e6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
Expand Up @@ -101,6 +101,11 @@ public LabelSpecifics[] getLabelSpecifics() {
return (labelSpecifics!=null) ? labelSpecifics : EMPTY_LABELS;
}

/**Check if the tool has additional variables set*/
public boolean hasAdditionalVariables() {
return additionalVariables != null;
}

public String getAdditionalVariables() {
return additionalVariables;
}
Expand All @@ -127,7 +132,9 @@ public CustomTool forNode(Node node, TaskListener log) throws IOException,

//FIXME: just a stub
public CustomTool forBuildProperties(Map<JobPropertyDescriptor,JobProperty> properties) {
return new CustomTool(getName(), getHome(), getProperties().toList(), getExportedPaths(), getLabelSpecifics(), toolVersion);
return new CustomTool(getName(), getHome(), getProperties().toList(),
getExportedPaths(), getLabelSpecifics(),
toolVersion, getAdditionalVariables());
}

/**
Expand Down
Expand Up @@ -176,11 +176,17 @@ public Launcher decorateLauncher(AbstractBuild build, final Launcher launcher,
throw new AbortException(ex.getMessage());
}

// Prepare additional variables
// Handle global options of the tool
//TODO: convert to label specifics?
PathsList installedPaths = installed.getPaths(node);
installed.correctHome(installedPaths);
paths.add(installedPaths);
if (installed.hasAdditionalVariables()) {
additionalVarInjectors.add(
EnvVariablesInjector.Create(installed.getAdditionalVariables()));
}

// Handle label-specific options of the tool
for (LabelSpecifics spec : installed.getLabelSpecifics()) {
if (!spec.appliesTo(node)) {
continue;
Expand Down
Expand Up @@ -40,6 +40,7 @@
import org.jvnet.hudson.test.HudsonTestCase;

import com.cloudbees.jenkins.plugins.customtools.CustomTool.DescriptorImpl;
import com.synopsys.arc.jenkinsci.plugins.customtools.LabelSpecifics;
import com.synopsys.arc.jenkinsci.plugins.customtools.multiconfig.MulticonfigWrapperOptions;
import com.synopsys.arc.jenkinsci.plugins.customtools.versions.ToolVersionConfig;

Expand Down Expand Up @@ -78,7 +79,26 @@ public void testBasicCase() throws Exception {
project.getBuildersList().add(b);
Future<FreeStyleBuild> build = project.scheduleBuild2(0);
assertBuildStatusSuccess(build);

}

// @Bug(19889). https://issues.jenkins-ci.org/browse/JENKINS-19889
//TODO: Just a stub for testing. Make the test automatic
public void testAdditionalVars() throws Exception {
hudson.setNumExecutors(0);
createSlave();
tools = hudson.getDescriptorByType(CustomTool.DescriptorImpl.class);
tools.setInstallations(createEnvPrinterTool("MyTrue", null, "TEST_ADD_VAR=test"));
FreeStyleProject project = createFreeStyleProject();
CustomToolInstallWrapper.SelectedTool selectedTool = new CustomToolInstallWrapper.SelectedTool("MyTrue");

CustomToolInstallWrapper wrapper = new CustomToolInstallWrapper(
new CustomToolInstallWrapper.SelectedTool[] { selectedTool }, MulticonfigWrapperOptions.DEFAULT, false);
project.getBuildWrappersList().add(wrapper);
Builder b = new Shell("env; mytrue");
project.getBuildersList().add(b);
Future<FreeStyleBuild> build = project.scheduleBuild2(0);
assertBuildStatusSuccess(build);
}

private CustomTool createTool(String name) throws IOException {
Expand All @@ -89,7 +109,19 @@ private CustomTool createTool(String name) throws IOException {
List<ToolProperty<ToolInstallation>> properties = new ArrayList<ToolProperty<ToolInstallation>>();
properties.add(new InstallSourceProperty(installers));

CustomTool installation = new CustomTool("MyTrue", null, properties, "./", null, ToolVersionConfig.DEFAULT);
CustomTool installation = new CustomTool("MyTrue", null, properties, "./", null, ToolVersionConfig.DEFAULT, null);
return installation;
}

//TODO: refactor and generalize
private CustomTool createEnvPrinterTool(String name, LabelSpecifics[] specifics, String additionalVars) throws IOException {
List<ToolInstaller> installers = new ArrayList<ToolInstaller>();
installers.add(new CommandInstaller(null, "ln -s `which true` mytrue", "./"));

List<ToolProperty<ToolInstallation>> properties = new ArrayList<ToolProperty<ToolInstallation>>();
properties.add(new InstallSourceProperty(installers));

CustomTool installation = new CustomTool(name, null, properties, "./", specifics, ToolVersionConfig.DEFAULT, additionalVars);
return installation;
}

Expand Down

0 comments on commit ed6e1e6

Please sign in to comment.