I am writing a pipeline job that will call another script to execute. The Jenkinsfile and script exist in the same directory and yet the job fails to find the script to run.
I am guessing this particular case has nothing to do with Jenkins pipelines, since it can be reproduced outside the Jenkins in the console. Once I got this issue due to DOS line-endings in my script which I ran in a pipeline's "sh()". Look at this example:
$ cat -v dos_formatted.sh
#! /bin/sh^M
pwd^M
$ cat script.sh
./dos_formatted.sh
$ sh -xe script.sh
+ ./dos_formatted.sh
script.sh: 1: script.sh: ./dos_formatted.sh: not found
It illustrates well that the "not found" message is misleading. The script is on the right place and the permissions are sufficient, but when you run it from another script it fails with such an error message.
The code of the Durable Task Plugin (https://github.com/jenkinsci/durable-task-plugin/blob/master/src/main/java/org/jenkinsci/plugins/durabletask/BourneShellScript.java) shows that the plugin runs the auto-generated script.sh as "sh -xe ...", therefore it's exactly our case.
The above described situation can happen if you "git clone" some (probably 3rd party) Git project and don't make sure that is was cloned with Unix-style LF.