Permalink
Browse files

[FIXED JENKINS-14109] Passing NODE_NAME as Node Parameter to downstre…

…am job not possible on master
  • Loading branch information...
imod committed Jun 25, 2012
1 parent 01b0a3c commit bb5a1c9bf91e22a801d298637582ebb277c61cf0
@@ -41,6 +41,11 @@
<version>2.12</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>token-macro</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
@@ -1,6 +1,5 @@
package org.jvnet.jenkins.plugins.nodelabelparameter.parameterizedtrigger;

import hudson.EnvVars;
import hudson.Extension;
import hudson.model.Action;
import hudson.model.TaskListener;
@@ -11,60 +10,48 @@

import java.io.IOException;

import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterValue;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* As this plugin is build against Jenkins1.398 and dynamic nodelabel assignment
* was only introduced with Jenkins1.417, this extension is marked as optional!
* As this plugin is build against Jenkins1.398 and dynamic nodelabel assignment was only introduced with Jenkins1.417, this extension is marked as optional!
*
* @author domi
*
*/
public class NodeLabelBuildParameter extends AbstractBuildParameters {

public final String name;
public final String nodeLabel;

@DataBoundConstructor
public NodeLabelBuildParameter(String name, String nodeLabel) {
this.name = name;
this.nodeLabel = nodeLabel;
}

public Action getAction(AbstractBuild<?, ?> build, TaskListener listener)
throws IOException, InterruptedException {
EnvVars env = build.getEnvironment(listener);
String labelExpanded = env.expand(nodeLabel);

LabelParameterValue parameterValue = new LabelParameterValue(name,
labelExpanded);
listener.getLogger().println("define: " + parameterValue);

return new ParametersAction(parameterValue);
}

@Extension(optional = true)
public static class DescriptorImpl extends
Descriptor<AbstractBuildParameters> {

// force loading of dependent class to disable extension early
// static {
// try {
// @SuppressWarnings("unused")
// Class<?> c = LabelParameterValue.class;
// } catch (Throwable e) {
// throw new NoClassDefFoundError(
// "'LabelParameterValue' - nodelabelparameter-plugin not installed, disable NodeLabelBuildParameter for parameterized-trigger-plugin");
// }
// }



@Override
public String getDisplayName() {
return "NodeLabel parameter";
}
}
public final String name;
public final String nodeLabel;

@DataBoundConstructor
public NodeLabelBuildParameter(String name, String nodeLabel) {
this.name = name;
this.nodeLabel = nodeLabel;
}

public Action getAction(AbstractBuild<?, ?> build, TaskListener listener) throws IOException, InterruptedException {
String labelExpanded = nodeLabel;
try {
labelExpanded = TokenMacro.expandAll(build, listener, labelExpanded);
} catch (MacroEvaluationException e) {
labelExpanded = nodeLabel;
e.printStackTrace(listener.getLogger());
}
LabelParameterValue parameterValue = new LabelParameterValue(name, labelExpanded);
listener.getLogger().println("define: " + parameterValue);

return new ParametersAction(parameterValue);
}

@Extension(optional = true)
public static class DescriptorImpl extends Descriptor<AbstractBuildParameters> {
@Override
public String getDisplayName() {
return "NodeLabel parameter";
}
}

}

0 comments on commit bb5a1c9

Please sign in to comment.