There seems to be no way to obtain a clean workspace using the multibranch pipeline job with the checkout scm statement. With the old workflow job type (not multibranch), it was not directly supported by the pipeline DSL, but it was possible to manually configure the Git SCM plugin with the CleanBeforeCheckout extension like this:
It does not seem possible to obtain this behavior while using the checkout scm shortcut in the multibranch pipeline job's Jenkinsfile.
Is it possible to pass a list of extensions to the checkout scm statement, without requiring a full specification of the repository URL and branch name in the DSL code?
- Allow passing the extensions class list to the checkout scm shortcut.
- Allow specifying the clean before checkout option in the multibranch job config XML/web page, and have the checkout scm statement automatically apply this.
- The Jenkins Workspace Cleanup plugin could be used to clean up the workspace, but it would wipe out the Git repository too, causing significant performance degradation because the project would have to be completely downloaded from the SCM server again.
- Add an explicit call to the external command git clean -ffdx in the Jenkinsfile before the checkout scm statement.
- Use the project build system (e.g. CMake/Ninja, make, Ant, Maven) to clean up before the build to ensure a clean and reproducible build is done. However, this is not as robust and comprehensive a solution as using Git to clean the workspace with git clean -ffdx, since the build system can only clean up files it knows about. Files are sometimes generated by the build that either the build system doesn't know about, or it just doesn't clean up.