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

GitSCMSource should offer extensions

    XMLWordPrintable

Details

    Description

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

      Attachments

        Issue Links

          Activity

            cbennett 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()
                    }
                }
            }
            
            
            cbennett 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() } } }
            jglick Jesse Glick added a comment -

            Probably implemented in PR 350; needs to be verified.

            jglick Jesse Glick added a comment - Probably implemented in PR 350; needs to be verified.
            markewaite Mark Waite added a comment -

            Included in git plugin 2.5.2, released July 2016

            markewaite Mark Waite added a comment - Included in git plugin 2.5.2, released July 2016
            adisutanto Adi Sutanto added a comment -

            markewaite, you mentioned "Included in git plugin 2.5.2, released July 2016". But the Git Plugin changelog doesn't mention anything about Git Clean Before Checkout in a Multibranch Pipeline job. Would you please teach us how to do it?

            adisutanto Adi Sutanto added a comment - markewaite , you mentioned "Included in git plugin 2.5.2, released July 2016". But the Git Plugin changelog doesn't mention anything about Git Clean Before Checkout in a Multibranch Pipeline job. Would you please teach us how to do it?
            markewaite Mark Waite added a comment - - edited

            adisutanto the changelog doesn't mention specific extensions because the change made them all available.

            Refer to the attached picture for the job configuration screen

            markewaite Mark Waite added a comment - - edited adisutanto the changelog doesn't mention specific extensions because the change made them all available. Refer to the attached picture for the job configuration screen
            adisutanto Adi Sutanto added a comment -

            markewaite, thank you very much!

            adisutanto Adi Sutanto added a comment - markewaite , thank you very much!
            trejkaz trejkaz added a comment -

            Trying to get into the configure page to configure this, but it's taking an awfully long time to load.

            trejkaz trejkaz added a comment - Trying to get into the configure page to configure this, but it's taking an awfully long time to load.

            People

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

              Dates

                Created:
                Updated:
                Resolved: