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