Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to add pre-build step for Jenkins pipeline?

Currently I'm able to use a post directive in my Jenkinsfile. Is there a way to trigger a pre-build step similar to this ?

  post {
    always {
      sh '''rm -rf build/workspace'''
    }
  }
like image 741
mirza Avatar asked Mar 04 '18 19:03

mirza


1 Answers

I believe this newer question may have the answer: Is there a way to run a pre-checkout step in declarative Jenkins pipelines?

pre is a cool feature idea, but doesn't exist yet. skipDefaultCheckout and checkout scm (which is the same as the default checkout) are the keys:

pipeline {
  agent { label 'docker' }
  options {
    skipDefaultCheckout true
  }
  stages {
    stage('clean_workspace_and_checkout_source') {
      steps {
        deleteDir()
        checkout scm
      }
    }
    stage('build') {
      steps {
        echo 'i build therefore i am'
      }
    }
  }
}
like image 200
Matt R Avatar answered Sep 19 '22 17:09

Matt R