Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-32540

Multibranch workflow and 'scm checkout' don't allow Git clean before checkout

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Duplicate
    • Icon: Major Major
    • pipeline
    • None
    • Jenkins v1.625.3 LTS
      Pipeline plugin v1.13

      Need to be able to build in a clean project checkout

      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:

          checkout([$class: 'GitSCM', branches: [[name: '*/master']],
              userRemoteConfigs: [[url: 'your_url_here']],
              extensions: [[$class: 'CleanBeforeCheckout']]])
      

      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?

      Possible solutions

      1. Allow passing the extensions class list to the checkout scm shortcut.
      2. Allow specifying the clean before checkout option in the multibranch job config XML/web page, and have the checkout scm statement automatically apply this.

      Possible alternative workarounds not using Git SCM clean before checkout option

      1. 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.
      2. Add an explicit call to the external command git clean -ffdx in the Jenkinsfile before the checkout scm statement.
      3. 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.

            jglick Jesse Glick
            cbennett Colin Bennett
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: