My Profile Photo

Ionut Gavrilut


DevOps Enthusiast | Linux System Administrator | Certified Jenkins Engineer


Jenkins Pipelines sh: source: not found / unexpected operator

When you have a sh step in a Pipeline and you want to run source command, you can get this error:

script.sh: source: not found

or

script.sh: unexpected operator

A possible cause of this error could be the sh interpreter. On an Ubuntu 16.04, default /bin/sh is a symlink to /bin/dash. Please check the symlink of the /bin/sh with:

ls -l /bin/sh

If this will return /bin/sh -> /bin/dash, it is a possible problem in Jenkins sh step. In order to make /bin/sh to point to /bin/bash, run:

sudo ln -sf /bin/bash /bin/sh

To go back to the default settings, and make the /bin/dash default for sh, run:

sudo ln -sf /bin/dash /bin/sh