Skip to content

Commit

Permalink
[FIXED JENKINS-22281] Output more informative logs when failing conve…
Browse files Browse the repository at this point in the history
…rting parameter values in compatibility mode.
  • Loading branch information
ikedam committed May 18, 2014
1 parent 6ffdde8 commit 5ce65de
Showing 1 changed file with 23 additions and 2 deletions.
@@ -1,10 +1,13 @@
package hudson.plugins.parameterizedtrigger;

import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Executor;
import hudson.model.Action;
import hudson.model.ParametersAction;
import hudson.model.ParameterDefinition;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Queue;
import hudson.model.ParameterValue;
import hudson.model.SimpleParameterDefinition;
import hudson.model.StringParameterDefinition;
Expand All @@ -16,7 +19,6 @@
import java.util.HashMap;
import java.util.logging.Logger;
import java.util.logging.Level;

import java.lang.RuntimeException;

/**
Expand Down Expand Up @@ -56,6 +58,20 @@ private static boolean canConvert(ParameterDefinition def, ParameterValue v) {
v.getClass().equals(StringParameterValue.class);
}

private static String getCurrentBuildName() {
Executor e = Executor.currentExecutor();
if(e == null) {
return null;
}

Queue.Executable task = e.getCurrentExecutable();
if(task == null || !(task instanceof AbstractBuild)) {
return null;
}

return ((AbstractBuild<?,?>)task).getFullDisplayName();
}

private static ParameterValue convertToDefinedType(Map<String, ParameterDefinition> defs, ParameterValue pv) {
String name = pv.getName();

Expand All @@ -67,9 +83,14 @@ private static ParameterValue convertToDefinedType(Map<String, ParameterDefiniti
return ((SimpleParameterDefinition)def).createValue(((StringParameterValue)pv).value);
} catch (RuntimeException e) {
if (System.getProperty("hudson.plugins.parameterizedtrigger.ProjectSpecificParametersActionFactory.compatibility_mode","false").equals("true")) {
String buildName = getCurrentBuildName();
Logger.getLogger(ProjectSpecificParameterValuesActionTransform.class.getName())
.log(Level.WARNING,
"Ignoring RuntimeException thrown while converting StringParameterValue. Falling back to original value.",
String.format(
"Ignoring RuntimeException thrown while converting StringParameterValue %s on %s. Falling back to original value.",
pv.getName(),
(buildName != null)?buildName:"PROJECT_CANNOT_RESOLVED"
),
e);
return pv;
} else {
Expand Down

0 comments on commit 5ce65de

Please sign in to comment.