Skip to content

Instantly share code, notes, and snippets.

@darinpope
Last active January 10, 2024 07:52
Show Gist options
  • Save darinpope/203ff5c9c33b028a7bf8c6ac4524c662 to your computer and use it in GitHub Desktop.
Save darinpope/203ff5c9c33b028a7bf8c6ac4524c662 to your computer and use it in GitHub Desktop.

Gist for https://youtu.be/S-M1GBzs2Ik

Documentation

Example #1

pipeline {
  agent any
  stages {
    stage('create files') {
      steps {
        sh '''
          touch file1.txt
          touch file2.txt
          touch file3.txt
        '''
      }
    }
    stage('list files') {
      steps {
        sh 'tree'
      }
    }
    stage('deleteDir') {
      steps {
        deleteDir()
      }
    }
    stage('list files again') {
      steps {
        sh 'tree'
      }
    }
  }
}

Example #2

pipeline {
  agent any
  stages {
    stage('create files') {
      steps {
        sh '''
          mkdir -p target
          touch file1.txt
          touch file2.txt
          touch file3.txt
          touch target/file4.txt
          touch target/file5.txt
          touch target/file6.txt
        '''
      }
    }
    stage('list files') {
      steps {
        sh 'tree'
      }
    }
    stage('deleteDir') {
      steps {
        dir('target') {
          deleteDir()
        }
      }
    }
    stage('list files again') {
      steps {
        sh 'tree'
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment