Bash not found in Jenkins declarative pipeline
Many lighter-weight Docker images, especially those built on top of Alpine Linux, don't contain GNU Bash.
The best solution here is to rewrite your script to not specifically require bash. Change its shebang line to #!/bin/sh
, and limit its syntax to what's allowed in the POSIX shell specification. This is more than sufficient for most straightforward "do A, B, C, and then D" style scripts; if you find yourself reaching for bash-specific features like arrays, consider a more powerful scripting language like Python.
Specifically in the single line
sh 'export PATH=/bin/bash:$PATH'
- Each
sh
command runs in its own execution environment with a clean environment, so environment variable settings from an earliersh
statement don't affect a later one; this statement is a no-op. - Elements of
$PATH
are directories, not individual files. /bin
is all but required to be on$PATH
and it is in all standard execution environments. (If/bin/bash
exists, then explicitbash -c '...'
commands and#!/bin/bash
shebang lines will find it.)
(The other frequent cause of problems like this is mixed Windows/Linux environments where the actual shebang line ends with a DOS-style CR/LF two-character newline and the environment can't run /bin/bash\r
.)