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

Cannot use /usr/bin/[ as a shell script step: wrapped in "..." after save

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • core

      1.479-SNAPSHOT. Create a freeform project, add a shell build step, and enter

      [ -n x ]
      

      for the script. (This should pass.) Now visit config.xml and you will see

          <hudson.tasks.Shell>
            <command>&quot;[ -n x ]&quot;</command>
          </hudson.tasks.Shell>
      

      which is clearly wrong and would fail:

      [test] $ /bin/sh -xe /tmp/hudson123.sh
      + [ -n x ]
      /tmp/hudson123.sh: 2: /tmp/hudson123.sh: [ -n x ]: not found
      Build step 'Execute shell' marked build as failure
      

      Workaround:

      test -n x
      

          [JENKINS-14827] Cannot use /usr/bin/[ as a shell script step: wrapped in "..." after save

          Jesse Glick added a comment -

          http://json-lib.sourceforge.net/changes-report.html#a2.2 notes "Extra quotes on string values with {} and []". Diffing 2.1 to 2.2 (there is no apparent SCM?) shows what seems to be an odd fix:

          @@ -2412,7 +2736,8 @@
                       if( value == null ){
                          return "";
                       }else{
          -               return str;
          +               String tmp = JSONUtils.stripQuotes( str );
          +               return JSONUtils.mayBeJSON( tmp ) ? tmp : str;
                       }
                    }
                 }else if( JSONUtils.isNumber( value ) ){
          @@ -2444,7 +2769,11 @@
                    throw new JSONException( "Null key." );
                 }
           
          -      this.properties.put( key, _processValue( value, jsonConfig ) );
          +      if( JSONUtils.isString( value ) && JSONUtils.mayBeJSON( String.valueOf( value ) ) ){
          +         this.properties.put( key, value );
          +      }else{
          +         this.properties.put( key, _processValue( value, jsonConfig ) );
          +      }
           
                 return this;
              }
          

          Theoretically https://github.com/aalmiray/Json-lib should show the details, though I am finding it hard to follow the history there - meaningless commit messages, no tags.

          Jesse Glick added a comment - http://json-lib.sourceforge.net/changes-report.html#a2.2 notes "Extra quotes on string values with {} and []". Diffing 2.1 to 2.2 (there is no apparent SCM?) shows what seems to be an odd fix: @@ -2412,7 +2736,8 @@ if ( value == null ){ return ""; } else { - return str; + String tmp = JSONUtils.stripQuotes( str ); + return JSONUtils.mayBeJSON( tmp ) ? tmp : str; } } } else if ( JSONUtils.isNumber( value ) ){ @@ -2444,7 +2769,11 @@ throw new JSONException( "Null key." ); } - this .properties.put( key, _processValue( value, jsonConfig ) ); + if ( JSONUtils.isString( value ) && JSONUtils.mayBeJSON( String .valueOf( value ) ) ){ + this .properties.put( key, value ); + } else { + this .properties.put( key, _processValue( value, jsonConfig ) ); + } return this ; } Theoretically https://github.com/aalmiray/Json-lib should show the details, though I am finding it hard to follow the history there - meaningless commit messages, no tags.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          src/main/jdk15/net/sf/json/JSONArray.java
          src/main/jdk15/net/sf/json/JSONObject.java
          src/test/java/net/sf/json/TestJSONArray.java
          src/test/java/net/sf/json/TestJSONObject.java
          http://jenkins-ci.org/commit/json-lib/71809a892de86906299898c9cae8ced6bf278141
          Log:
          JENKINS-14827 Misinterpretation of "[...]".

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/jdk15/net/sf/json/JSONArray.java src/main/jdk15/net/sf/json/JSONObject.java src/test/java/net/sf/json/TestJSONArray.java src/test/java/net/sf/json/TestJSONObject.java http://jenkins-ci.org/commit/json-lib/71809a892de86906299898c9cae8ced6bf278141 Log: JENKINS-14827 Misinterpretation of " [...] ".

          Jesse Glick added a comment -

          I committed 71809a8 in our fork which seems to fix the problem, but am not sure what I might be missing. Anyway, if you like the fix please release, and use in Stapler / Jenkins.

          Jesse Glick added a comment - I committed 71809a8 in our fork which seems to fix the problem, but am not sure what I might be missing. Anyway, if you like the fix please release, and use in Stapler / Jenkins.

          sogabe added a comment -

          It works for me.

          sogabe added a comment - It works for me.

          Jesse Glick added a comment -

          @sogabe: just checked and it is still broken in 1.492. No one has released the patched json-lib much less integrated it into Stapler and then Jenkins. IIRC Kohsuke was going to try to rebase json-lib against upstream since our version is quite old.

          Jesse Glick added a comment - @sogabe: just checked and it is still broken in 1.492. No one has released the patched json-lib much less integrated it into Stapler and then Jenkins. IIRC Kohsuke was going to try to rebase json-lib against upstream since our version is quite old.

          sogabe added a comment -

          @jglick: I have installed json-lib 2.1-rev8-SNAPSHOT, which contains your patch locally and re-built jenkins with it.it works.
          It is good idea to rebase json-lib, if it takes a long time, we should release it.

          sogabe added a comment - @jglick: I have installed json-lib 2.1-rev8-SNAPSHOT, which contains your patch locally and re-built jenkins with it.it works. It is good idea to rebase json-lib, if it takes a long time, we should release it.

          I believe the fix is now integrated with json-lib:2.4-jenkins-1 getting into the trunk.

          Kohsuke Kawaguchi added a comment - I believe the fix is now integrated with json-lib:2.4-jenkins-1 getting into the trunk.

          Jesse Glick added a comment -

          Does seem to be fixed now.

          Jesse Glick added a comment - Does seem to be fixed now.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          changelog.html
          http://jenkins-ci.org/commit/jenkins/f8f9462b6c4ed1c83da9fed53e88fe0b8d034890
          Log:
          JENKINS-14827 Noting.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: changelog.html http://jenkins-ci.org/commit/jenkins/f8f9462b6c4ed1c83da9fed53e88fe0b8d034890 Log: JENKINS-14827 Noting.

          dogfood added a comment -

          Integrated in jenkins_main_trunk #2453
          JENKINS-14827 Noting. (Revision f8f9462b6c4ed1c83da9fed53e88fe0b8d034890)

          Result = SUCCESS
          Jesse Glick : f8f9462b6c4ed1c83da9fed53e88fe0b8d034890
          Files :

          • changelog.html

          dogfood added a comment - Integrated in jenkins_main_trunk #2453 JENKINS-14827 Noting. (Revision f8f9462b6c4ed1c83da9fed53e88fe0b8d034890) Result = SUCCESS Jesse Glick : f8f9462b6c4ed1c83da9fed53e88fe0b8d034890 Files : changelog.html

            kohsuke Kohsuke Kawaguchi
            jglick Jesse Glick
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: