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

Scripts always fail when run in build, but succeed from command line

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • postbuildscript-plugin
    • None
    • Ubuntu 16.04.3 LTS
      Jenkins 2.89.4
      PostBuildScript plugin 2.5.0

      config.xml testScript.sh Each time my build runs, PostBuildScript is saying there is an error (project names redacted): 

      [PostBuildScript] - Executing post build scripts.
      [PostBuildScript] - Executing the script /var/lib/jenkins/workspace/<project>/<module>/mvp-contexts/updateVms.sh with parameters [/var/lib/jenkins/workspace/<project>].
      [MCP] $  /bin/bash /tmp/jenkins4164249000057985231.sh /var/lib/jenkins/workspace/<project>
      [PostBuildScript] - [ERROR] Problem occurred: Error while executing script
      Build step 'Execute Scripts' changed build result to FAILURE
      Build step 'Execute Scripts' marked build as failure
      

      But if I SSH into the Jenkins machine and su to the Jenkins user, I can copy that command from the [MCP] line and run it just fine.

      I've tried it with just a hello world echo statement in the script with the same result.

      The parameter is workspace project location so the script can reference workspace files.

      EDIT

      I think I've figured it out. If there is a space after the shebang (#!) in the script, it fails in the plugin, but running the command from the log output works. I've attached my config.xml and testScript.sh for reproducing the bug.

          [JENKINS-49681] Scripts always fail when run in build, but succeed from command line

          Daniel Heid added a comment -

          Thanks for submitting this issue! I must reproduce the problem in order to fix it. Could you please provide the script and the job configuration (config.xml)?

          Daniel Heid added a comment - Thanks for submitting this issue! I must reproduce the problem in order to fix it. Could you please provide the script and the job configuration (config.xml)?

          Sam Jones added a comment -

          I've updated the issue with a working config/script to reproduce the error, along with what I think the problem is.

          Sam Jones added a comment - I've updated the issue with a working config/script to reproduce the error, along with what I think the problem is.

          Code changed in jenkins
          User: Daniel Heid
          Path:
          README.md
          pom.xml
          src/main/java/org/jenkinsci/plugins/postbuildscript/service/CommandExecutor.java
          src/test/java/org/jenkinsci/plugins/postbuildscript/service/CommandExecutorIT.java
          src/test/resources/shebang_with_spaces.sh
          http://jenkins-ci.org/commit/postbuildscript-plugin/a72f93f18317ada38215a9d8569d5a79005ef74f
          Log:
          JENKINS-49681 Allowing spaces in front of interpreter

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Heid Path: README.md pom.xml src/main/java/org/jenkinsci/plugins/postbuildscript/service/CommandExecutor.java src/test/java/org/jenkinsci/plugins/postbuildscript/service/CommandExecutorIT.java src/test/resources/shebang_with_spaces.sh http://jenkins-ci.org/commit/postbuildscript-plugin/a72f93f18317ada38215a9d8569d5a79005ef74f Log: JENKINS-49681 Allowing spaces in front of interpreter

          Daniel Heid added a comment -

          Okay, there will no longer be problems with spaces in front of the shebang with the upcoming version 2.5.1. Thanks for making the PostBuildScript plugin better!

          Daniel Heid added a comment - Okay, there will no longer be problems with spaces in front of the shebang with the upcoming version 2.5.1. Thanks for making the PostBuildScript plugin better!

            dheid Daniel Heid
            imnotpete Sam Jones
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: