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:
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.
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?