I'd like to execute a shell file from within the shared library itself.
here is the path of the file:
libraryFoo/resources/foo.sh
my PipelineUtils package path within the library: libraryFoo/src/f1.org.pipeline/PipelineUtils
class PipelineUtils implements Serializable {
...
def shell() {
pipeline.sh(
script: resources/foo.sh,
returnStdout: true
)
}
}
and it is implemented in the pipeline:
@Library('libraryFoo') _
import f1.org.pipeline.PipelineUtils
...
stage('Tag SCM') {
def utils = new PipelineUtils()
utils.shell()
}
In order to read files from the resources folder of your shared library you will need to use a designated step created exactly for this called libraryResource:
So in your case you can use it to load the script and run it using the
shstep, assumingpipelineis your object that holds the script context it will look like:Alternatively you can also load the script and rewrite it to a local file if you need it for future use: