GitSCM.extensions such as CleanBeforeCheckout cannot currently be configured on GitSCMSource.

          [JENKINS-31924] GitSCMSource should offer extensions

          Jesse Glick created issue -
          Jesse Glick made changes -
          Link New: This issue is duplicated by JENKINS-32540 [ JENKINS-32540 ]

          Colin Bennett added a comment - - edited

          Workaround for "Clean Before Checkout" Equivalent

          I tried a few ways to get the equivalent of a Git Clean Before Checkout behavior in a Multibranch Pipeline job. Here is what is working for me now: using a manual call to git clean, falling back on deleteDir() pipeline statement if there is no existing Git repository in the workspace:

          node {
              gitClean()
              checkout scm
              /* ... rest of the build ... */
          }
          
          /**
           * Clean a Git project workspace.
           * Uses 'git clean' if there is a repository found.
           * Uses Pipeline 'deleteDir()' function if no .git directory is found.
           */
          def gitClean() {
              timeout(time: 60, unit: 'SECONDS') {
                  if (fileExists('.git')) {
                      echo 'Found Git repository: using Git to clean the tree.'
                      // The sequence of reset --hard and clean -fdx first
                      // in the root and then using submodule foreach
                      // is based on how the Jenkins Git SCM clean before checkout
                      // feature works.
                      bat 'git reset --hard'
                      // Note: -e is necessary to exclude the temp directory
                      // .jenkins-XXXXX in the workspace where Pipeline puts the
                      // batch file for the 'bat' command.
                      bat 'git clean -ffdx -e ".jenkins-*/"'
                      bat 'git submodule foreach --recursive git reset --hard'
                      bat 'git submodule foreach --recursive git clean -ffdx'
                  }
                  else
                  {
                      echo 'No Git repository found: using deleteDir() to wipe clean'
                      deleteDir()
                  }
              }
          }
          
          

          Colin Bennett added a comment - - edited Workaround for "Clean Before Checkout" Equivalent I tried a few ways to get the equivalent of a Git Clean Before Checkout behavior in a Multibranch Pipeline job. Here is what is working for me now: using a manual call to git clean , falling back on deleteDir() pipeline statement if there is no existing Git repository in the workspace: node { gitClean() checkout scm /* ... rest of the build ... */ } /** * Clean a Git project workspace. * Uses 'git clean' if there is a repository found. * Uses Pipeline 'deleteDir()' function if no .git directory is found. */ def gitClean() { timeout(time: 60, unit: 'SECONDS' ) { if (fileExists( '.git' )) { echo 'Found Git repository: using Git to clean the tree.' // The sequence of reset --hard and clean -fdx first // in the root and then using submodule foreach // is based on how the Jenkins Git SCM clean before checkout // feature works. bat 'git reset --hard' // Note: -e is necessary to exclude the temp directory // .jenkins-XXXXX in the workspace where Pipeline puts the // batch file for the 'bat' command. bat 'git clean -ffdx -e ".jenkins-*/" ' bat 'git submodule foreach --recursive git reset --hard' bat 'git submodule foreach --recursive git clean -ffdx' } else { echo 'No Git repository found: using deleteDir() to wipe clean' deleteDir() } } }
          Jesse Glick made changes -
          Link New: This issue is blocking JENKINS-32552 [ JENKINS-32552 ]
          Jesse Glick made changes -
          Link New: This issue is related to JENKINS-32767 [ JENKINS-32767 ]
          Jesse Glick made changes -
          Link New: This issue is duplicated by JENKINS-32658 [ JENKINS-32658 ]
          Jesse Glick made changes -
          Link New: This issue is duplicated by JENKINS-33022 [ JENKINS-33022 ]
          Patrick Wolf made changes -
          Labels Original: multibranch workflow New: 2.0 multibranch workflow
          Jesse Glick made changes -
          Assignee New: Jesse Glick [ jglick ]
          Jesse Glick made changes -
          Epic Link New: JENKINS-35386 [ 171179 ]

            Unassigned Unassigned
            jglick Jesse Glick
            Votes:
            16 Vote for this issue
            Watchers:
            23 Start watching this issue

              Created:
              Updated:
              Resolved: