17

I am testing the jenkins job-dsl plugin. I have an existing project where the setting 'Delete workspace before build starts' is enabled.

I have the following DSL defined:

job("$basePath/my-project") {
    scm {
        git {
            remote {
                name('origin')
                url('git@bitbucket.org:my-organisation/my-project.git')
            }
            branch('*/develop')
            extensions {
                wipeOutWorkspace()
                submoduleOptions {
                    recursive()
                }
            }
        }
    }
}

It seems this gives a configuration that is not really the same, it shows a "Wipe out repository & force clone" option. Are these options really the same thing in the end or are there different behaviours?

Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211

2 Answers2

12

There is in general no difference between both options.

They are provided by different plugins:

  • Wipe out repository & force clone is part of the Git Plugin and only suitable as extension of the git plugin
  • Delete workspace before build starts is part of the Workspace Clean Plugin

The main differences between the Workspace Clean Plugin and the Git Plugin:

  • Not bound to Git SCM only
  • Allows the usage of ant file pattern to delete only some files or directories
CSchulz
  • 10,882
  • 11
  • 60
  • 114
  • 21
    In case anybody wonders how to configure the 2nd option with the Job DSL plugin: `job('my-job') { wrappers { preBuildCleanup() } }` – Wim Deblauwe May 31 '16 at 12:52
  • 1
    Note that "Delete workspace before build starts" is the first thing that happens. If for some reason you want to do something before that you can use the pre-scm plugin to act before the "Wipe out repository & force clone". – junebob Aug 31 '16 at 14:27
2

An important behavior of the Git plugin's "Wipe out repository & force clone" option is that it will delete only the repository subdirectory if you have selected one in the "Check out to a subdirectory" option. It will leave the rest of your workspace alone. This doesn't appear in the documentation as far as I can tell.

You can achieve similar behavior with the Workspace Cleanup plugin by specifying the clone subdirectory in the "Pattern for files to be deleted" Advanced configuration section.

The end result is exactly the same, but in my observations the Git plugin deletion was 5 seconds faster than the Workspace Cleanup plugin.

mikewaters
  • 3,668
  • 3
  • 28
  • 22