Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-17009

Parameters with newlines should be stored as TextParameterValue


    • Similar Issues:


      For one of my Jobs I need multiple lines of text in one parameter, e.g.

      In the parameterized build trigger plugin I specify this parameter with "\n":


      The "\n" correctly passes the parameter with newline characters to an upcoming biuld.

      In the build.xml of the jenkins-build, the newlines are stored normally, however there are problems later on if other plugins work with this data because the parameter-type is "StringParameterValue" instead of "TextParameterValue":


      E.g. if I use the rebuild-plugin to re-trigger the build later on, it seems to cut off the newlines and pass the string in one single line, which causes the rebuild to fail:

      ... -Dsonar.projectKey=preismonitor-lokalsonar.projectName=preismonitor-lokal ...

      The following patch creates a TextParameterValue if the value contains newlines. This makes this work locally for me:

      diff --git a/src/main/java/hudson/plugins/parameterizedtrigger/PredefinedBuildParameters.java b/src/main/java/hudson/plugins/parameterizedtrigger/PredefinedBuildParameters.java
      index b1cbc73..26f2e50 100644
      --- a/src/main/java/hudson/plugins/parameterizedtrigger/PredefinedBuildParameters.java
      +++ b/src/main/java/hudson/plugins/parameterizedtrigger/PredefinedBuildParameters.java
      @@ -2,13 +2,14 @@
       import hudson.EnvVars;
       import hudson.Extension;
      -import hudson.model.AbstractBuild;
       import hudson.model.Action;
      -import hudson.model.Descriptor;
       import hudson.model.ParameterValue;
      +import hudson.model.TaskListener;
      +import hudson.model.AbstractBuild;
      +import hudson.model.Descriptor;
       import hudson.model.ParametersAction;
       import hudson.model.StringParameterValue;
      -import hudson.model.TaskListener;
      +import hudson.model.TextParameterValue;
       import java.io.IOException;
       import java.util.ArrayList;
      @@ -38,8 +39,14 @@
       		List<ParameterValue> values = new ArrayList<ParameterValue>();
       		for (Map.Entry<Object, Object> entry : p.entrySet()) {
      -			values.add(new StringParameterValue(entry.getKey().toString(),
      -					env.expand(entry.getValue().toString())));
      +			// support multi-line parameters correctly
      +			if(entry.getValue().toString().contains("\n")) {
      +				values.add(new TextParameterValue(entry.getKey().toString(),
      +						env.expand(entry.getValue().toString())));
      +			} else {
      +				values.add(new StringParameterValue(entry.getKey().toString(),
      +						env.expand(entry.getValue().toString())));
      +			}
       		return new ParametersAction(values);




            • Assignee:
              huybrechts huybrechts
              centic centic
            • Votes:
              1 Vote for this issue
              5 Start watching this issue


              • Created: