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

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

    • 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.

          [JENKINS-32540] Multibranch workflow and 'scm checkout' don't allow Git clean before checkout

          Marcus Philip added a comment -

          I don't think JENKINS-31924 is a perfect duplicate of this. AFAIK there is no way to do a git clean when you use the checkout scm step. And this is the preferred way for checking out the same repo as the Jenkinsfile. Unless I am mistaken, or there is another issue for this, I believe this issue should be reopened.

          AFAIK, I cannot use the checkout([$class: 'GitSCM', ... workaround since there is no simple way to get the git commit to checkout.

          Which of the current workarounds to you recommend?

          Marcus Philip added a comment - I don't think JENKINS-31924 is a perfect duplicate of this. AFAIK there is no way to do a git clean when you use the checkout scm step. And this is the preferred way for checking out the same repo as the Jenkinsfile. Unless I am mistaken, or there is another issue for this, I believe this issue should be reopened. AFAIK, I cannot use the checkout([$class: 'GitSCM', ... workaround since there is no simple way to get the git commit to checkout. Which of the current workarounds to you recommend?

          I created the bug JENKINS-37817 since you cannot pull out the values in scm to use them in checkout.

          Christian Höltje added a comment - I created the bug JENKINS-37817 since you cannot pull out the values in scm to use them in checkout .

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

              Created:
              Updated:
              Resolved: