Skip to content
Permalink
Browse files

[JENKINS-30357] Fixed NPE when using ParameterizedBuildSelector in Wo…

…rkflow or using undefined variables in ParameterizedBuildSelector.
  • Loading branch information
ikedam committed Sep 21, 2015
1 parent bab56aa commit 6ddc88a0e0609bde83d8aecbd90170f254cc8fcf
@@ -365,12 +365,24 @@ public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace, @Nonn
upgradeIfNecessary(((AbstractBuild)build).getProject());
}

EnvVars env;
EnvVars env = build.getEnvironment(listener);
if (build instanceof AbstractBuild) {
env = build.getEnvironment(listener);
env.overrideAll(((AbstractBuild)build).getBuildVariables()); // Add in matrix axes..
} else {
env = new EnvVars();
// Abstract#getEnvironment(TaskListener) put build parameters to
// environments, but Run#getEnvironment(TaskListener) doesn't.
// That means we can't retrieve build parameters from WorkflowRun
// as it is a subclass of Run, not of AbstractBuild.
// We need expand build parameters manually.
// See JENKINS-26694, JENKINS-30357 for details.
for(ParametersAction pa: build.getActions(ParametersAction.class)) {
// We have to extract parameters manally as ParametersAction#buildEnvVars
// (overrides EnvironmentContributingAction#buildEnvVars)
// is applicable only for AbstractBuild.
for(ParameterValue pv: pa.getParameters()) {
pv.buildEnvironment(build, env);
}
}
}

PrintStream console = listener.getLogger();
@@ -23,11 +23,15 @@
*/
package hudson.plugins.copyartifact;

import java.util.logging.Level;
import java.util.logging.Logger;

import hudson.EnvVars;
import hudson.Extension;
import hudson.model.Descriptor;
import hudson.model.Job;
import hudson.model.Run;

import org.kohsuke.stapler.DataBoundConstructor;

/**
@@ -37,6 +41,7 @@
*/
public class ParameterizedBuildSelector extends BuildSelector {
private String parameterName;
private static final Logger LOG = Logger.getLogger(ParameterizedBuildSelector.class.getName());

@DataBoundConstructor
public ParameterizedBuildSelector(String parameterName) {
@@ -49,7 +54,12 @@ public String getParameterName() {

@Override
public Run<?,?> getBuild(Job<?,?> job, EnvVars env, BuildFilter filter, Run<?,?> parent) {
return BuildSelectorParameter.getSelectorFromXml(env.get(parameterName))
String xml = env.get(getParameterName());
if (xml == null) {
LOG.log(Level.WARNING, "{0} is not defined", getParameterName());
return null;
}
return BuildSelectorParameter.getSelectorFromXml(xml)
.getBuild(job, env, filter, parent);
}

0 comments on commit 6ddc88a

Please sign in to comment.
You can’t perform that action at this time.