Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean builds with Multibranch Workflow

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.

like image 814
Chris Jones Avatar asked Dec 10 '15 22:12

Chris Jones


People also ask

What is the difference between pipeline and Multibranch pipeline in Jenkins?

Jenkins Pipeline Vs. Multibranch Pipeline. A multibranch pipeline is meant for building multiple branches from a repository and deploy to multiple environments if required. A pipeline job supports both pipeline steps to be added in Jenkins configuration and form SCM.

What is the use of Multibranch pipeline?

The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages and executes Pipelines for branches which contain a Jenkinsfile in source control.

How do you run the Multibranch pipeline?

Head over to your Jenkins instance and create a new item. Enter a name for the job, and select the “Multibranch Pipeline” option at the end of the screen. Then, click on the OK button. In the next screen, go to the “Branch sources” tab, click on the “Add source” button, and choose “Git” from the dropdown menu.


2 Answers

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.

checkout([
    $class: 'GitSCM',
    branches: scm.branches,
    extensions: scm.extensions + [[$class: 'CleanBeforeCheckout']],
    userRemoteConfigs: scm.userRemoteConfigs
])

It's still not perfect because you have to create a new object :(

like image 22
hEngi Avatar answered Oct 23 '22 05:10

hEngi


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:

stage ('Clean') {
    deleteDir()
}

stage ('Checkout') {
    checkout scm 
}
like image 80
Brad Albright Avatar answered Oct 23 '22 03:10

Brad Albright