We are using the Pipeline Shared Libraries plugin to factorize the code common to our different Jenkins pipelines.
From its documentation, it offers a resources
top-level folder for non-Groovy files. As we rely on different bash functions, we would like to host them in a separate .sh
file (thus they could also be used by other processes than Jenkins).
The same documentation tells us about using libraryResource
step to load those resource files. We can successfully call this method within our Groovy script, giving it our resource file name as argument (function.sh
). But from here, we were not able to find a way to invoke the foofoo
function defined in function.sh
from the same Groovy script.
sh "foofoo" #error: foofoo is not defined
We also tried to first source it like this:
sh "source function.sh && foofoo"
But it fails at the source
step, stating that function.sh
is not found.
What would be the correct procedure to invoke a bash function defined in function.sh