Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unstashing a stash in multiple stages throughout a pipeline

I am using stash\unstash in my pipeline, and wondered could you unstash in multiple stages?

So for example:

stage('One') {
  steps {
    echo 'Stage one...'
    stash includes: 'dist/**/*', name: 'builtSources'
    dir('/some-dir/deploy') {
      unstash 'builtSources'
    }
  }
}
stage('Two') {
  steps {
    echo 'Stage two...'
    node('OtherNode') {
      dir('/some-other-dir/deploy') {
        unstash 'builtSources'
      }
    }
  }
}

So can I retrieve a stash made in an earlier stage, in any of the following stages, any number of times?

like image 822
mindparse Avatar asked Mar 29 '17 14:03

mindparse


People also ask

What is stash in Jenkins pipeline?

stash : Stash some files to be used later in the buildSaves a set of files for later use on any node/workspace in the same Pipeline run. By default, stashed files are discarded at the end of a pipeline run.

How do you skip a step in Jenkins pipeline?

You can skip stages in declarative pipelines using when , so the following should work. stages { stage('Deploy') { when { equals expected: true, actual: Deploy } steps { // ... } } }


1 Answers

Yes, you can definitely unstash the files multiple times across multiple stages and make the best use of it.

like image 107
Karthick Avatar answered Nov 16 '22 02:11

Karthick