Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save darinpope/a2f5be7c624e76f00fbbfdab27d699a0 to your computer and use it in GitHub Desktop.
Save darinpope/a2f5be7c624e76f00fbbfdab27d699a0 to your computer and use it in GitHub Desktop.

Gist for https://youtu.be/admAfAYoVRo

Documentation

Job Definitions

test1

pipeline {
  agent any
  stages {
    stage('check file') {
      steps {
        script {
          if (fileExists('file.txt')) {
            echo "File file.txt found!"
          }
        }
      }
    }
  }
}

test2

pipeline {
  agent any
  stages {
    stage('check file') {
      when {
        expression {
          return fileExists('file.txt')
        }
      }
      steps {
        echo "File file.txt found!"
      }
    }
  }
}

test3

pipeline {
  agent any
  stages {
    stage('create file') {
      steps {
        sh 'touch file.txt'
      }
    }
    stage('check file') {
      when {
        expression {
          return fileExists('file.txt')
        }
      }
      steps {
        echo "File file.txt found!"
      }
    }
  }
}

test4

pipeline {
  agent any
  stages {
    stage('check directory') {
      when {
        expression {
          return fileExists('src/main')
        }
      }
      steps {
        echo "Directory src/main found!"
      }
    }
  }
}

test5

pipeline {
  agent any
  stages {
    stage('create directory') {
      steps {
        sh 'mkdir -p src/main'
      }
    }
    stage('check directory') {
      when {
        expression {
          return fileExists('src/main')
        }
      }
      steps {
        echo "Directory src/main found!"
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment