I am writing a pipeline job that will call another script to execute. The Jenkinsfile and script exist in the same directory and yet the job fails to find the script to run.
This is the relevant bit of script;
stage ('Update') {
try {
dir('jenkins/pipeline/update-jenkins-plugins-ppln') {
sh 'ls -l'
sh 'update-plugins.sh'
}
}
which returns the following error;
[update-jenkins-plugins-ppln] Running shell script
+ ls -l
total 8
-rw-r--r-- 1 jenkins jenkins 2441 Dec 20 09:34 Jenkinsfile
-rwxr-xr-x 1 jenkins jenkins 506 Dec 19 14:06 update-plugins.sh
[Pipeline] sh
[update-jenkins-plugins-ppln] Running shell script
+ update-plugins.sh
/var/lib/jenkins/workspace/update-jenkins-plugins-ppln/jenkins/pipeline/update-jenkins-plugins-ppln@tmp/durable-11cefdd0/script.sh: 2: /var/lib/jenkins/workspace/update-jenkins-plugins-ppln/jenkins/pipeline/update-jenkins-plugins-ppln@tmp/durable-11cefdd0/script.sh: update-plugins.sh: not found
As you can see, the pathing I'm using is correct because according to the ls
the file I need update-plugins.sh
is in the directory I've pathed to. For some reason though, when actually searching for the script Jenkins is adding @tmp/durable-8d48734f/script.sh
onto the path.
Various troubleshooting:
Why is Jenkins adding the @tmp bit, and is there a way to prevent this behavior?
Click New Item on your Jenkins home page, enter a name for your (pipeline) job, select Pipeline, and click OK. In the Script text area of the configuration screen, enter your pipeline syntax.
Or by visiting the sub-URL /script on your Jenkins instance. Visit "Manage Jenkins" > "Manage Nodes" . Select any node to view the status page. In the menu on the left, a menu item is available to open a "Script Console" on that specific agent. It’s also possible to run scripts from the controller Script Console on individual agents.
This feature can be accessed from "Manage Jenkins" > "Script Console" . Or by visiting the sub-URL /script on your Jenkins instance. Visit "Manage Jenkins" > "Manage Nodes" . Select any node to view the status page. In the menu on the left, a menu item is available to open a "Script Console" on that specific agent.
Because of the power offered by the Jenkins Script Console, Jenkins and its agents should never be run as the root user (on Linux) or system administrator on any other flavor of OS. Videos linked in this page demonstrate and discuss security warnings.
I guess your pwd is not in PATH so you have to call it like this: sh './update-plugins.sh'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With