Skip to content

Instantly share code, notes, and snippets.

@darinpope
Last active April 17, 2024 11:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save darinpope/74462757661613ac9b8cdd742c3918a2 to your computer and use it in GitHub Desktop.
Save darinpope/74462757661613ac9b8cdd742c3918a2 to your computer and use it in GitHub Desktop.

Gist for https://youtu.be/0GQZzLlnUws

Documentation

Example #1 - default

pipeline {
  agent none

  stages {
    stage('Hello') {
      agent { label 'linux' }
      steps {
        sh '''
          touch file.txt
          mkdir -p target
          touch target/file2.jar
          touch target/file3.war
          tree
        '''
        stash(name: 'myStash')
      }
    }
    stage('check the file') {
      agent { label 'macos' }
      steps {
        unstash 'myStash'
        sh 'tree'
      }
    }
  }
}

Example #2 - includes

pipeline {
  agent none

  stages {
    stage('Hello') {
      agent { label 'linux' }
      steps {
        sh '''
          touch file.txt
          mkdir -p target
          touch target/file2.jar
          touch target/file3.war
          tree
        '''
        stash(name: 'myStash', includes: '**/*.war')
      }
    }
    stage('check the file') {
      agent { label 'macos' }
      steps {
        unstash 'myStash'
        sh 'tree'
      }
    }
  }
}

Example #3 - excludes

pipeline {
  agent none

  stages {
    stage('Hello') {
      agent { label 'linux' }
      steps {
        sh '''
          touch file.txt
          mkdir -p target
          touch target/file2.jar
          touch target/file3.war
          tree
        '''
        stash(name: 'myStash', excludes: '**/*.war')
      }
    }
    stage('check the file') {
      agent { label 'macos' }
      steps {
        unstash 'myStash'
        sh 'tree'
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment