Issue
I have a jenkins pipeline that builds a java artifact, copies it to a directory and then attempts to execute a external script.
I am using this syntax within the pipeline script to execute the external script
dir('/opt/script-directory') {
sh './run.sh'
}
The script is just a simple docker build script, but the build will fail with this exception:
java.io.IOException: Failed to mkdirs: /opt/script-directory@tmp/durable-ae56483c
The error is confusing because the script does not create any directories. It is just building a docker image and placing the freshly built java artifact in that image.
If I create a different job in jenkins that executes the external script as its only build step and then call that job from my pipeline script using this syntax:
build 'docker test build'
everything works fine, the script executes within the other job and the pipeline continues as expected.
Is this the only way to execute a script that is external to the workspace?
What am I doing wrong with my attempt at executing the script from within the pipeline script?
Solution
The issue is that the jenkins user (or whatever the user is that runs the Jenkins slave process) does not have write permission on /opt
and the sh
step wants to create the script-directory@tmp/durable-ae56483c
sub-directory there.
Either remove the dir
block and use the absolute path to the script:
sh '/opt/script-directory/run.sh'
or give write permission to jenkins user to folder /opt
(not preferred for security reasons)
Answered By - Gergely Toth