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

Parameters with newlines should be stored as TextParameterValue

      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":

      PROJECTPROPERTIES=sonar.projectKey=preismonitor-lokal\nsonar.projectName=preismonitor-lokal

      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":

      <hudson.model.StringParameterValue>
                  <name>PROJECTPROPERTIES</name>
                  <value>sonar.projectKey=preismonitor-lokal
      sonar.projectName=preismonitor-lokal</value>
                </hudson.model.StringParameterValue>

      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);
      

          [JENKINS-17009] Parameters with newlines should be stored as TextParameterValue

          cjo9900 added a comment -

          Can you create a pull request on github for this?
          Thanks

          cjo9900 added a comment - Can you create a pull request on github for this? Thanks

          centic added a comment -

          centic added a comment - Done: https://github.com/jenkinsci/parameterized-trigger-plugin/pull/36

          Code changed in jenkins
          User: zalan-axis
          Path:
          src/main/java/hudson/plugins/parameterizedtrigger/FileBuildParameters.java
          src/main/java/hudson/plugins/parameterizedtrigger/PredefinedBuildParameters.java
          src/main/resources/hudson/plugins/parameterizedtrigger/FileBuildParameters/config.jelly
          src/main/resources/hudson/plugins/parameterizedtrigger/FileBuildParameters/help-textParamValueOnNewLine.html
          src/main/resources/hudson/plugins/parameterizedtrigger/PredefinedBuildParameters/config.jelly
          src/main/resources/hudson/plugins/parameterizedtrigger/PredefinedBuildParameters/help-textParamValueOnNewLine.html
          http://jenkins-ci.org/commit/parameterized-trigger-plugin/f65c60cec97c68bf63b8f828bcc379080a45b756
          Log:
          JENKINS-17009 - Parameters with newlines should be stored as TextParam… (#95)

          • JENKINS-17009: Parameters with newlines should be stored as TextParameterValue
          • Add option for inserting TextParameterValue for multiline parameters.

          When newlines are encountered in parameters the most appropriate parameter
          type is TextParameterValue. For backward compatibility this feature
          is disabled by default.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: zalan-axis Path: src/main/java/hudson/plugins/parameterizedtrigger/FileBuildParameters.java src/main/java/hudson/plugins/parameterizedtrigger/PredefinedBuildParameters.java src/main/resources/hudson/plugins/parameterizedtrigger/FileBuildParameters/config.jelly src/main/resources/hudson/plugins/parameterizedtrigger/FileBuildParameters/help-textParamValueOnNewLine.html src/main/resources/hudson/plugins/parameterizedtrigger/PredefinedBuildParameters/config.jelly src/main/resources/hudson/plugins/parameterizedtrigger/PredefinedBuildParameters/help-textParamValueOnNewLine.html http://jenkins-ci.org/commit/parameterized-trigger-plugin/f65c60cec97c68bf63b8f828bcc379080a45b756 Log: JENKINS-17009 - Parameters with newlines should be stored as TextParam… (#95) JENKINS-17009 : Parameters with newlines should be stored as TextParameterValue Add option for inserting TextParameterValue for multiline parameters. When newlines are encountered in parameters the most appropriate parameter type is TextParameterValue. For backward compatibility this feature is disabled by default.

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

              Created:
              Updated: