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

GitSCMSource should offer extensions

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

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

        Attachments

          Issue Links

            Activity

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

            Probably implemented in PR 350; needs to be verified.

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

            Included in git plugin 2.5.2, released July 2016

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

            Mark Waite, 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?

            Show
            adisutanto Adi Sutanto added a comment - Mark Waite , 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?
            Hide
            markewaite Mark Waite added a comment - - edited

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

            Refer to the attached picture for the job configuration screen

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

            Mark Waite, thank you very much!

            Show
            adisutanto Adi Sutanto added a comment - Mark Waite , thank you very much!
            Hide
            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.

            Show
            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

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

                Dates

                • Created:
                  Updated:
                  Resolved: