How to clean before checkout in a Multibranch Pipeline

8,241 views
Skip to first unread message

Francois Marot

unread,
Jun 20, 2017, 10:38:24 AM6/20/17
to Jenkins Users
I converted an old style job to Multibranch Pipeline with a Jenkinsfile (declarative syntax).
Problem is that files from previous build are present in new builds and cause numerous problems once packaged.
In the old-style job, I used to activate the "clean before checkout " param of the git plugin.

Problem is that I have no scm step now as it is a Multibranch Pipeline job and Jenkins itself is smart enough to checkout from git (in order to access the Jenksinfile describing the job).
So how can I force Jenkins to "clean before checkout" ?

I have seen answers where the previous build deletes the workspace after completion but I find it not satisfying to rely on the behavior of previous jobs to complete one job.

Regards,
François

Mark Waite

unread,
Jun 20, 2017, 10:44:08 AM6/20/17
to jenkins...@googlegroups.com
On Tue, Jun 20, 2017 at 8:38 AM Francois Marot <francoi...@gmail.com> wrote:
I converted an old style job to Multibranch Pipeline with a Jenkinsfile (declarative syntax).
Problem is that files from previous build are present in new builds and cause numerous problems once packaged.
In the old-style job, I used to activate the "clean before checkout " param of the git plugin.

Problem is that I have no scm step now as it is a Multibranch Pipeline job and Jenkins itself is smart enough to checkout from git (in order to access the Jenksinfile describing the job).
So how can I force Jenkins to "clean before checkout" ?

You can insert a checkout step into your pipeline definition that will include the "CleanBeforeCheckout" extension.  An example is https://github.com/MarkEWaite/jenkins-bugs/blob/JENKINS-43931/Jenkinsfile .

You can perform a shell step "git clean -xffd" as your first pipeline step if you prefer.

Mark Waite
 
I have seen answers where the previous build deletes the workspace after completion but I find it not satisfying to rely on the behavior of previous jobs to complete one job.

Regards,
François

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/dfec64d8-92fc-49a4-9a09-82c575707d26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Francois Marot

unread,
Jun 20, 2017, 11:03:21 AM6/20/17
to Jenkins Users
Your answer is so obvious I feel ashamed of myself ! ;)
I used: bat "git clean -dfx" which is IMHO the best.
I find the additional checkout step very redundant as Jenkins itself checkout the files in order to get the Jenkinsfile.

Great thanks Mark

Mark Waite

unread,
Jun 20, 2017, 11:09:35 AM6/20/17
to jenkins...@googlegroups.com
On Tue, Jun 20, 2017 at 9:03 AM Francois Marot <francoi...@gmail.com> wrote:
Your answer is so obvious I feel ashamed of myself ! ;)
I used: bat "git clean -dfx" which is IMHO the best.
I find the additional checkout step very redundant as Jenkins itself checkout the files in order to get the Jenkinsfile.


That seems reasonable to me.  Declarative pipeline has the very nice feature that the job starts with a checkout of the branch.  It's great that you're using it.

I sometimes need tuning of how the checkout is performed (sparse checkout, shallow clone, reference repository, large file support, specific refspec, etc.).  Those types of tuning require changing the checkout itself, without the elegance of a simple call to a command line program.

Mark Waite
 
Great thanks Mark

On Tuesday, June 20, 2017 at 4:44:08 PM UTC+2, Mark Waite wrote:


On Tue, Jun 20, 2017 at 8:38 AM Francois Marot <francoi...@gmail.com> wrote:
I converted an old style job to Multibranch Pipeline with a Jenkinsfile (declarative syntax).
Problem is that files from previous build are present in new builds and cause numerous problems once packaged.
In the old-style job, I used to activate the "clean before checkout " param of the git plugin.

Problem is that I have no scm step now as it is a Multibranch Pipeline job and Jenkins itself is smart enough to checkout from git (in order to access the Jenksinfile describing the job).
So how can I force Jenkins to "clean before checkout" ?

You can insert a checkout step into your pipeline definition that will include the "CleanBeforeCheckout" extension.  An example is https://github.com/MarkEWaite/jenkins-bugs/blob/JENKINS-43931/Jenkinsfile .

You can perform a shell step "git clean -xffd" as your first pipeline step if you prefer.

Mark Waite
 
I have seen answers where the previous build deletes the workspace after completion but I find it not satisfying to rely on the behavior of previous jobs to complete one job.

Regards,
François

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages