stash jenkins @script directory

Viewed 357

I'm using the very handy Remote Jenkins Provider plugin for retrieving the Jenkinsfile from a different repository than the source code. The Jenkinsfile script and some helper files are downloaded in the @scripts directory in the job workspace. This works as expected.

The problem I'm facing is that the pipeline runs in multiple nodes and the @script directory is only available in the master node (the one that retrieved it from the repository). I'm trying to use stash/unstash for sharing this directory across nodes:

node('master'){
    stage('save script'){
        sh "ls -l ${env.WORKSPACE}@script/"
        stash name: 'scripts', includes: "${env.WORKSPACE}@script/**"
    }
}

pipeline {
    agent { label 'worker' }
    stages {
        stage('build') {
            steps {
                unstash name: 'scripts'
                sh "${env.WORKSPACE}@script/helper.sh"
            }
        }
    }
}

The output of the ls step shows that both the Jenkinsfile and the helper script are there:

-rw-r--r-- 1 jenkins jenkins 166 Jul 10 16:53 Jenkinsfile
-rwxr-xr-x 1 jenkins jenkins  29 Jul 10 15:18 helper.sh

However, the build fails in the stash step with this message: ERROR: No files included in stash ‘scripts’

Notice that if I run the whole pipeline in the same master node, without stash/unstash, it works.

How can I share the @script directory across nodes?

0 Answers
Related