mirza
mirza

Reputation: 5793

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'''
    }
  }

Upvotes: 13

Views: 25276

Answers (1)

Matt R
Matt R

Reputation: 160

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'
      }
    }
  }
}

Upvotes: 7

Related Questions