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

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

XMLWordPrintable

    • 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.

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

              Created:
              Updated:
              Resolved: