Using Multibranch Workflow, the command to check out looks like
checkout scm
I can't find a way to tell Jenkins to perform a clean checkout. By "clean," I mean it should remove all files from the workspace that aren't under version control.
Using Multibranch Workflow, the command to check out looks like
checkout scm
I can't find a way to tell Jenkins to perform a clean checkout. By "clean," I mean it should remove all files from the workspace that aren't under version control.
I run into the same problem and here is my workaround. I created a new scm object for the checkout and extended the extensions with the CleanBeforeCheckout. But i kept the other configurations like branches and userRemoteConfigs.
It's still not perfect because you have to create a new object :(
Behaviors can be added when configuring the source.
clean before checkout
,clean after checkout
andWipe out repository and force clone
. This removes the need to add logic to the declarative / scripted pipelines.Jenkins currently contains a page to generate groovy pipeline syntax. Selecting the checkout step you should be able to add all the additional options that you're used to.
I generated the following which should do what you want:
First, you can not assume that a workflow job has a workspace as it was for freestyle jobs. Actually, a workflow job can use more than one workspace (one for each
node
orws
block).Said that, what I'm going to propose is a kind of hacky: modify the scm object before checkout to set up a
CleanCheckout
extension (you will have to approve some calls there).But I'd prefer Christopher Orr's proposal, use a shell step after
checkout
(sh 'git clean -fdx'
).I'm not sure if this answers the original question or not (I couldn't tell if the intention was to leave some files in the workspace) but why not just remove the workspace first, this would allow a clean checkout: