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;

  • git commands not respecting io redirection
  • Asking for password when pushing to gitlab?
  • calling git diff in pre-commit shell script
  • sh.exe": emacs: command not found (Git bash Windows)
  • Bash. Line-by-line output into another procedure
  • Reuse GIT_WORK_TREE in post-receive hook to rm a few files
  • 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?

  • How to ignore directory globally in Git?
  • Getting a folder into GitHub having tried before incorrectly
  • How to write or package a Git server as a Java Servlet or Java webapp?
  • Unable to setup pods (error: RPC failed; curl 56 SSLRead() return error -9806)
  • How can I view branches other than master in gitweb?
  • Android Studio - checkout a *branch* from GitHub
  • 2 Solutions collect form web for “Jenkins Pipeline job can't find script due to @tmp path being created”

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

    Have you tried using the jenkins workspace environment variable WORKSPACE (absolute path of the workspace)? With that your line would look something like this:

    sh '${WORKSPACE}/jenkins/pipeline/update-jenkins-plugins-ppln/update-plugins.sh'
    
    Git Baby is a git and github fan, let's start git clone.