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

shell pipeline step cannot use relative path to shell

XMLWordPrintable

    • durable-task 1.28

      There is some difference between free-style project shell build step and the pipeline `sh` step. If I set in jenkins global configuration `bash` as the "Shell Executable", then free-style project works and calls `bash` from the PATH on the slave. The pipeline `sh` step fails like this though:

      [pipeline-test-job] Running shell script
      sh: /home/jenkins/workspace/pipeline-test-akostadi@tmp/durable-2ff6e6ae/script.sh: bash: bad interpreter: No such file or directory
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      ERROR: script returned exit code 126
      Finished: FAILURE
      

      The use case is that some systems like MacOS ship with an old bash version under /bin/sh. And we want to not be limited in shell scripts by that version. Since proper bash should be installed in other locations on such slaves, we need to run `bash` from PATH. But also can't hardcode `bash` absolute path because it is still `/bin/bash` on normal linux slaves.

      I'm reading through ShellStep.java and BourneShellScript.java.

      It looks like it launches `sh -c cmd` but I don't see how the global setting is applied, even less I understand why it fails. At the same time free-style projects work fine with this setting on all slaves.

      I think this difference between free-style and pipeline might be related to JENKINS-44341 also.

      Any clue what exactly might be the difference and how it could be fixed?

            olivergondza Oliver Gondža
            akostadinov akostadinov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: