Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Pipeline job can't find script due to @tmp path being created

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:

  • I read that you have to checkout the branch again even if you're already checking it out to get the Jenkinsfile, so I am.
  • I have ssh'd into the Jenkins box to check and yes, the script is there.

Why is Jenkins adding the @tmp bit, and is there a way to prevent this behavior?

like image 927
Alex Avatar asked Dec 20 '16 15:12

Alex


People also ask

How do I create a pipeline job in Jenkins?

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.

How do I run a script in Jenkins?

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.

How do I view the status of a Jenkins script?

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.

Should Jenkins be run as root or system administrator?

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.


1 Answers

I guess your pwd is not in PATH so you have to call it like this: sh './update-plugins.sh'

like image 200
izzekil Avatar answered Sep 21 '22 20:09

izzekil