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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Component/s: postbuildscript-plugin
    • Labels:
      None
    • Environment:
      Ubuntu 16.04.3 LTS
      Jenkins 2.89.4
      PostBuildScript plugin 2.5.0
    • Similar Issues:

      Description

      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.

        Attachments

          Activity

          Hide
          dheid 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)?

          Show
          dheid 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)?
          Hide
          imnotpete 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.

          Show
          imnotpete 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.
          Hide
          scm_issue_link 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

          Show
          scm_issue_link 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
          Hide
          dheid 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!

          Show
          dheid 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!

            People

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

              Dates

              • Created:
                Updated:
                Resolved: