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

Jenkins CLI cannot handle arguments with equals signs ("=")

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • cli, remoting
    • None
    • stable-1.565.3

      The Jenkins CLI can pass in parameters to a parameterized build. It uses the "-p" option for this. The arguments are parsed using args4j. The version of args4j that has been incorporated has a bug in the MapOptionHandler code where it will not accept a parameter value that has an equals sign ("=") in it; instead it will take everything up to the equals sign. The problem appears to be fixed in newer args4j code.

          [JENKINS-21160] Jenkins CLI cannot handle arguments with equals signs ("=")

          Damien Nozay added a comment -

          I meant it did not work properly.

          here is what I tried in the script console:

          import org.kohsuke.args4j.Argument;
          import org.kohsuke.args4j.CmdLineException;
          import org.kohsuke.args4j.CmdLineParser;
          import org.kohsuke.args4j.Option;
          import org.kohsuke.args4j.spi.BooleanOptionHandler;
          
          import java.io.File;
          import java.io.IOException;
          import java.util.ArrayList;
          import java.util.List;
          
          import java.util.Map.Entry;
          import java.util.Map;
          import java.util.HashMap;
          
          public class SampleMain {
              @Option(name="-p",usage="Specify the build parameters in the key=value format.")
              Map<String,String> parameters = new HashMap<String, String>();
          
              Map<String,String> parameters2 = new HashMap<String, String>();
              @Option(name="-P",usage="Specify the build parameters in the key=value format.")
              protected void setParameter(final String property)  {
                  int eqIndex =  property.indexOf("=");
                  if (eqIndex == -1) {
                      throw new IllegalArgumentException("build parameters must be specified in the form: <key>=<value>");
                  }
                  parameters2.put(property.substring(0,eqIndex), property.substring(eqIndex+1));
              }
          
          }
          
          def test(String[] args) {
              println("test with args: " + args)
              main = new SampleMain()
              CmdLineParser parser = new CmdLineParser(main);
              parser.parseArgument(args)
              for (Entry<String, String> e : main.parameters.entrySet()) {
                   String name = e.getKey();
                   String value = e.getValue();
                   println("[parameters]  " + name + ' := ' + value);
              }
              for (Entry<String, String> e : main.parameters2.entrySet()) {
                   String name = e.getKey();
                   String value = e.getValue();
                   println("[parameters2] " + name + ' := ' + value);
              }
          }
          
          // test('-p', 'key=value', '-P', 'key=value')
          test('-p', 'key=value=more', '-P', 'key=value=more')
          

          even though it shows

          args4j:args4j:2.0.23

          in the "about" form.

          Damien Nozay added a comment - I meant it did not work properly. here is what I tried in the script console: import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.CmdLineParser; import org.kohsuke.args4j.Option; import org.kohsuke.args4j.spi.BooleanOptionHandler; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; import java.util.Map; import java.util.HashMap; public class SampleMain { @Option(name= "-p" ,usage= "Specify the build parameters in the key=value format." ) Map< String , String > parameters = new HashMap< String , String >(); Map< String , String > parameters2 = new HashMap< String , String >(); @Option(name= "-P" ,usage= "Specify the build parameters in the key=value format." ) protected void setParameter( final String property) { int eqIndex = property.indexOf( "=" ); if (eqIndex == -1) { throw new IllegalArgumentException( "build parameters must be specified in the form: <key>=<value>" ); } parameters2.put(property.substring(0,eqIndex), property.substring(eqIndex+1)); } } def test( String [] args) { println( "test with args: " + args) main = new SampleMain() CmdLineParser parser = new CmdLineParser(main); parser.parseArgument(args) for (Entry< String , String > e : main.parameters.entrySet()) { String name = e.getKey(); String value = e.getValue(); println( "[parameters] " + name + ' := ' + value); } for (Entry< String , String > e : main.parameters2.entrySet()) { String name = e.getKey(); String value = e.getValue(); println( "[parameters2] " + name + ' := ' + value); } } // test( '-p' , 'key=value' , '-P' , 'key=value' ) test( '-p' , 'key=value=more' , '-P' , 'key=value=more' ) even though it shows args4j:args4j:2.0.23 in the "about" form.

          Damien Nozay added a comment -

          jenkins about page:

          org.jenkins-ci.main:remoting:2.46
          args4j:args4j:2.0.23
          

          https://github.com/jenkinsci/remoting/blob/remoting-2.46/pom.xml#L108-L113

              <dependency>
                <groupId>args4j</groupId>
                <artifactId>args4j</artifactId>
                <version>2.0.16</version>
                <scope>provided</scope>
              </dependency>
          

          Damien Nozay added a comment - jenkins about page: org.jenkins-ci.main:remoting:2.46 args4j:args4j:2.0.23 https://github.com/jenkinsci/remoting/blob/remoting-2.46/pom.xml#L108-L113 <dependency> <groupId>args4j</groupId> <artifactId>args4j</artifactId> <version>2.0.16</version> <scope>provided</scope> </dependency>

          Damien Nozay added a comment -

          remoting is pulling older args4j version.

          Damien Nozay added a comment - remoting is pulling older args4j version.

          Damien Nozay added a comment -

          Damien Nozay added a comment - https://github.com/jenkinsci/remoting/pull/26

          Damien Nozay added a comment -

          remoting not only depends on args4j but also bundles it.

          <execution>
            <id>bundle-arg4j</id>
            <phase>process-classes</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.outputDirectory}</outputDirectory>
              <includeScope>provided</includeScope>
              <includeArtifactIds>args4j</includeArtifactIds>
              <includeGroupIds>args4j</includeGroupIds>
            </configuration>
          </execution>
          

          Damien Nozay added a comment - remoting not only depends on args4j but also bundles it. <execution> <id>bundle-arg4j</id> <phase>process-classes</phase> <goals> <goal>unpack-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.outputDirectory}</outputDirectory> <includeScope>provided</includeScope> <includeArtifactIds>args4j</includeArtifactIds> <includeGroupIds>args4j</includeGroupIds> </configuration> </execution>

          Code changed in jenkins
          User: Damien Nozay
          Path:
          core/pom.xml
          http://jenkins-ci.org/commit/jenkins/ec2b7fcc8d9542cd7b39d3c7594b3ba6d174f6b0
          Log:
          JENKINS-21160: update pom.xml to warn about mismatched args4j

          in some circumstances, you may use some older args4j (coming from remoting) when the jenkins about page shows a different version.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Damien Nozay Path: core/pom.xml http://jenkins-ci.org/commit/jenkins/ec2b7fcc8d9542cd7b39d3c7594b3ba6d174f6b0 Log: JENKINS-21160 : update pom.xml to warn about mismatched args4j in some circumstances, you may use some older args4j (coming from remoting) when the jenkins about page shows a different version.

          Code changed in jenkins
          User: Oleg Nenashev
          Path:
          core/pom.xml
          http://jenkins-ci.org/commit/jenkins/a22e20d4670560d98d577c26bfd8e45fa72ecb2f
          Log:
          Merge pull request #1419 from dnozay/patch-1

          JENKINS-21160: update pom.xml to warn about mismatched args4j

          Compare: https://github.com/jenkinsci/jenkins/compare/8e0b87c0ace4...a22e20d46705

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Oleg Nenashev Path: core/pom.xml http://jenkins-ci.org/commit/jenkins/a22e20d4670560d98d577c26bfd8e45fa72ecb2f Log: Merge pull request #1419 from dnozay/patch-1 JENKINS-21160 : update pom.xml to warn about mismatched args4j Compare: https://github.com/jenkinsci/jenkins/compare/8e0b87c0ace4...a22e20d46705

          Code changed in jenkins
          User: Kohsuke Kawaguchi
          Path:
          changelog.html
          core/pom.xml
          pom.xml
          http://jenkins-ci.org/commit/jenkins/72e0b9c53a15306e0a7b7117100f4d1b7ec250b8
          Log:
          [FIXED JENKINS-6167 JENKINS-21251 JENKINS-21160]

          Integrated a newer version of remoting & args4j

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Kohsuke Kawaguchi Path: changelog.html core/pom.xml pom.xml http://jenkins-ci.org/commit/jenkins/72e0b9c53a15306e0a7b7117100f4d1b7ec250b8 Log: [FIXED JENKINS-6167 JENKINS-21251 JENKINS-21160] Integrated a newer version of remoting & args4j

          dogfood added a comment -

          Integrated in jenkins_main_trunk #4021
          [FIXED JENKINS-6167 JENKINS-21251 JENKINS-21160] (Revision 72e0b9c53a15306e0a7b7117100f4d1b7ec250b8)

          Result = SUCCESS
          kohsuke : 72e0b9c53a15306e0a7b7117100f4d1b7ec250b8
          Files :

          • changelog.html
          • core/pom.xml
          • pom.xml

          dogfood added a comment - Integrated in jenkins_main_trunk #4021 [FIXED JENKINS-6167 JENKINS-21251 JENKINS-21160] (Revision 72e0b9c53a15306e0a7b7117100f4d1b7ec250b8) Result = SUCCESS kohsuke : 72e0b9c53a15306e0a7b7117100f4d1b7ec250b8 Files : changelog.html core/pom.xml pom.xml

          Oleg Nenashev added a comment -

          Oleg Nenashev added a comment - Fixed on March 2015th https://github.com/jenkinsci/jenkins/commit/72e0b9c53a15306e0a7b7117100f4d1b7ec250b8

            Unassigned Unassigned
            rjbell4 Bob Bell
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: