Jenkins declarative pipelines offer a post directive to execute code after the stages have finished. Is there a similar thing to run code before the stages are running, and most importantly, before the SCM checkout?
For example something along the lines of:
pre {
always {
rm -rf ./*
}
}
This would then clean the workspace of my build before the source code is checked out.
For the moment there are no
pre-build
steps but for the purpose you are looking for, it can be done in the pipeline job configurarion and also multibranch pipeline jobs, when you define where is your jenkinsfile, choose Additional Behaviours -> Wipe out repository & force clone.If you do not really want to delete everything and save some network usage, you can just use this other option: Additional Behaviours -> Clean before checkout.
This one will not delete the workspace but just reset the repository to the original state and pull new changes if there are some.
pre
is a cool feature idea, but doesn't exist yet.skipDefaultCheckout
andcheckout scm
(which is the same as the default checkout) are the keys: