Skip to content

Commit

Permalink
Merge pull request #4 from synopsys-arc-oss/JENKINS-18707-matrix-buil…
Browse files Browse the repository at this point in the history
…d-support

New option: Skip tools installation on MatrixBuild's master job
  • Loading branch information
oleg-nenashev committed Jul 17, 2013
2 parents 53001e1 + fb74c91 commit 33caac6
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 17 deletions.
Expand Up @@ -18,13 +18,15 @@

import com.synopsys.arc.jenkinsci.plugins.customtools.CustomToolException;
import com.synopsys.arc.jenkinsci.plugins.customtools.PathsList;
import com.synopsys.arc.jenkinsci.plugins.customtools.multiconfig.MulticonfigWrapperOptions;
import hudson.AbortException;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.Platform;
import hudson.Proc;
import hudson.Util;
import hudson.matrix.MatrixBuild;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
Expand Down Expand Up @@ -76,12 +78,14 @@ public CustomTool toCustomTool() {
}

private SelectedTool[] selectedTools = new SelectedTool[0];

private MulticonfigWrapperOptions multiconfigOptions;

@DataBoundConstructor
public CustomToolInstallWrapper(SelectedTool[] selectedTools) {
public CustomToolInstallWrapper(SelectedTool[] selectedTools, MulticonfigWrapperOptions multiconfigOptions) {
this.selectedTools = (selectedTools != null) ? selectedTools : new SelectedTool[0];
this.multiconfigOptions = (multiconfigOptions != null) ? multiconfigOptions : MulticonfigWrapperOptions.DEFAULT;
}

@Override
public Environment setUp(AbstractBuild build, Launcher launcher,
BuildListener listener) throws IOException, InterruptedException {
Expand Down Expand Up @@ -119,6 +123,14 @@ public Launcher decorateLauncher(AbstractBuild build, final Launcher launcher,
final EnvVars homes = new EnvVars();
final PathsList paths = new PathsList();

// Handle multi-configuration build
if (MatrixBuild.class.isAssignableFrom(build.getClass())) {
listener.getLogger().println("[CustomTools] - Skipping installation of tools at the master job");
if (multiconfigOptions.isSkipMasterInstallation()) {
return launcher;
}
}

//each tool can export zero or many directories to the PATH
for (CustomTool tool : customTools()) {
//this installs the tool if necessary
Expand All @@ -133,7 +145,7 @@ public Launcher decorateLauncher(AbstractBuild build, final Launcher launcher,
throw new AbortException(ex.getMessage());
}

listener.getLogger().println(tool.getName()+" is installed at "+ installed.getHome());
listener.getLogger().println("[CustomTools] - "+tool.getName()+" is installed at "+ installed.getHome());

homes.put(tool.getName()+"_HOME", installed.getHome());
paths.add(installed.getPaths(Computer.currentComputer().getNode()));
Expand Down Expand Up @@ -167,6 +179,24 @@ private EnvVars toEnvVars(String[] envs) {
public Descriptor<BuildWrapper> getDescriptor() {
return DESCRIPTOR;
}

/**
* Check if build has specific multi-configuration options
* @return True if multi-configuration options are configured
* @since 0.3
*/
public boolean hasMulticonfigOptions() {
return multiconfigOptions != MulticonfigWrapperOptions.DEFAULT;
}

/**
* Gets multi-configuration job parameters.
* @return
* @since 0.3
*/
public MulticonfigWrapperOptions getMulticonfigOptions() {
return multiconfigOptions;
}

@Extension
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
Expand All @@ -192,10 +222,9 @@ public CustomTool[] getInstallations() {
@Override
public boolean configure(StaplerRequest req, JSONObject json)
throws hudson.model.Descriptor.FormException {
// TODO Auto-generated method stub
//TODO: Auto-generated method stub
return super.configure(req, json);
}

}
}
}
}

@@ -0,0 +1,36 @@
/*
* Copyright 2013 Oleg Nenashev <nenashev@synopsys.com>, Synopsys Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.synopsys.arc.jenkinsci.plugins.customtools.multiconfig;

import org.kohsuke.stapler.DataBoundConstructor;

/**
* Provides specific options for multi-configuration jobs.
* @author Oleg Nenashev <nenashev@synopsys.com>, Synopsys Inc.
*/
public class MulticonfigWrapperOptions {
private boolean skipMasterInstallation;
public static final MulticonfigWrapperOptions DEFAULT = new MulticonfigWrapperOptions(false);

@DataBoundConstructor
public MulticonfigWrapperOptions(boolean skipInstallationOnMaster) {
this.skipMasterInstallation = skipInstallationOnMaster;
}

public boolean isSkipMasterInstallation() {
return skipMasterInstallation;
}
}
@@ -1,4 +1,5 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="" description="">
<f:repeatable name="selectedTools" var="selectedTool" items="${instance.selectedTools}"
add="${%Add Tool}" header="Tools to install">
Expand All @@ -18,7 +19,15 @@
</f:entry>
</table>
</f:repeatable>
<table width="100%">
<f:optionalBlock name="multiconfigOptions"
title="${%Multi-configuration jobs specific parameters}" checked="${instance.hasMulticonfigOptions()}"
help="/plugin/custom-tools-plugin/CustomToolInstallWrapper/help-multiconfigOptions.html">
<f:entry help="/plugin/custom-tools-plugin/CustomToolInstallWrapper/help-skipInstallationOnMaster.html">
<f:checkbox title="Don't install tools at the master job" field="skipInstallationOnMaster" checked="${instance.multiconfigOptions.isSkipMasterInstallation()}"/>
</f:entry>
</f:optionalBlock>
</table>
</f:entry>


</j:jelly>

This file was deleted.

@@ -0,0 +1,3 @@
<div>
Provides specific options for multi-configuration builds.
</div>
@@ -0,0 +1,3 @@
<div>
Skips installation of tools at the matrix master job.
</div>
Expand Up @@ -42,6 +42,7 @@
import com.cloudbees.jenkins.plugins.customtools.CustomTool;
import com.cloudbees.jenkins.plugins.customtools.CustomToolInstallWrapper;
import com.cloudbees.jenkins.plugins.customtools.CustomTool.DescriptorImpl;
import com.synopsys.arc.jenkinsci.plugins.customtools.multiconfig.MulticonfigWrapperOptions;


public class CustomToolInstallerTest extends HudsonTestCase {
Expand Down Expand Up @@ -72,7 +73,7 @@ public void testBasicCase() throws Exception {
CustomToolInstallWrapper.SelectedTool selectedTool = new CustomToolInstallWrapper.SelectedTool("MyTrue");

CustomToolInstallWrapper wrapper = new CustomToolInstallWrapper(
new CustomToolInstallWrapper.SelectedTool[] { selectedTool });
new CustomToolInstallWrapper.SelectedTool[] { selectedTool }, MulticonfigWrapperOptions.DEFAULT);
project.getBuildWrappersList().add(wrapper);
Builder b = new Shell("echo $PATH; mytrue");
project.getBuildersList().add(b);
Expand Down

0 comments on commit 33caac6

Please sign in to comment.