• Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Major Major
    • git-plugin
    • Node: Win10
      Jenkins: 2.387.1
      Git-Plugin: 5.0.0

      This sparse chechout config shall only checkout 'my_path' but nothing is checkout. The log do not show any sparse checkout configuration which could intigate that only 'my_path' will be checkout.

      checkout scmGit(
          branches: [[name: "refs/heads/${env.BRANCH_NAME}"]],
          extensions: [
              cleanBeforeCheckout(),
              [
                  $class: 'SparseCheckoutPaths',
                  sparseCheckoutPaths: [
                      [path: 'my_path']
                  ]
              ]
          ],
          userRemoteConfigs: [[credentialsId: 'my_cred_id', url: "my_url"]]
      )
      

      creates this log:

      The recommended git tool is: git
      using credential my_cred_id
      Fetching changes from the remote Git repository
      Cleaning workspace
       > git rev-parse --resolve-git-dir d:\my_path\.git # timeout=10
       > git config remote.origin.url https://my_repo.git # timeout=10
       > git rev-parse --verify HEAD # timeout=10
      Resetting working tree
       > git reset --hard # timeout=10
       > git clean -fdx # timeout=10
      Fetching upstream changes from https://my_repo.git
       > git --version # timeout=10
       > git --version # 'git version 2.40.0.windows.1'
      using GIT_ASKPASS to set credentials my cred
       > git fetch --tags --force --progress -- https://my_repo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
      Checking out Revision 09f52abbb863f29eb0c01cf340e50fc739e95185 (refs/remotes/origin/my_branch)
       > git rev-parse "refs/remotes/origin/my_branch^{commit}" # timeout=10
       > git config core.sparsecheckout # timeout=10
       > git read-tree -mu HEAD # timeout=10
       > git checkout -f 09f52abbb863f29eb0c01cf340e50fc739e95185 # timeout=10
      Commit message: "My message"
      

       

          [JENKINS-70858] Fail to sparse checkout folder

          Mark Waite added a comment - - edited

          I can't duplicate the problem as described. I created a Pipeline job (not a multibranch Pipeline job) and confirmed that the checkout only included the src directory and the pom.xml file. The Pipeline script looks like this:

          pipeline {
              agent {
                  label 'windows'
              }
          
              stages {
                  stage('Sparse Checkout') {
                      steps {
                          checkout scmGit(
                              branches: [[name: 'master']], 
                              extensions: [[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'pom.xml'], [path: 'src']]]],
                              userRemoteConfigs: [[url: 'https://github.com/jenkinsci/elastic-axis-plugin.git']])
                          bat 'dir'
                      }
                  }
              }
          }
          

          Maybe you are using a multibranch Pipeline and have forgotten to include the skipDefaultCheckout(true) option?

          Mark Waite added a comment - - edited I can't duplicate the problem as described. I created a Pipeline job (not a multibranch Pipeline job) and confirmed that the checkout only included the src directory and the pom.xml file. The Pipeline script looks like this: pipeline { agent { label 'windows' } stages { stage('Sparse Checkout') { steps { checkout scmGit( branches: [[name: 'master']], extensions: [[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'pom.xml'], [path: 'src']]]], userRemoteConfigs: [[url: 'https://github.com/jenkinsci/elastic-axis-plugin.git']]) bat 'dir' } } } } Maybe you are using a multibranch Pipeline and have forgotten to include the skipDefaultCheckout(true) option?

          Mark Waite added a comment -

          eugenskt if I don't see a response from you within the next two weeks, I'll close this as "Cannot reproduce".

          Mark Waite added a comment - eugenskt if I don't see a response from you within the next two weeks, I'll close this as "Cannot reproduce".

          We use a multibranch Pipeline job with skipDefaultCheckout (is the (true) necessary? Here it is described without https://www.jenkins.io/doc/book/pipeline/syntax/)

          options {
                  timeout(time: 2, unit: 'HOURS')
                  skipDefaultCheckout()
                  parallelsAlwaysFailFast()
          }
          

          Also, the stage doing the sparce checkout is running on different node. So full pipe looks like:

          pipeline {
              agent {
                  node {label 'node1'}
              }
              options {
                  timeout(time: 2, unit: 'HOURS')
                  skipDefaultCheckout()
              }
          
              stages {
                  stage('Build & Checks') {
                      checkout scm
                      ...
                  }
          
                  stage('Smoke Test') {
                      agent {
                          node {label 'node2'}
                      }
                      steps {
                          echo("Running on node: ${NODE_NAME}")
                          script {
                              checkout scmGit(
                                  branches: [[name: "refs/heads/${env.BRANCH_NAME}"]],
                                  extensions: [
                                      cleanBeforeCheckout(),
                                      [
                                          $class: 'SparseCheckoutPaths',
                                          sparseCheckoutPaths: [
                                              [path: 'my_path']
                                          ]
                                      ]
                                  ],
                                  userRemoteConfigs: [[credentialsId: 'my_cred_id', url: "my_url"]]
                              )
                          }
                      }
                  }
              }
          }
          
          
          

          Eugen Kleinschmidt added a comment - We use a multibranch Pipeline job with skipDefaultCheckout (is the (true) necessary? Here it is described without https://www.jenkins.io/doc/book/pipeline/syntax/ ) options { timeout(time: 2, unit: 'HOURS' ) skipDefaultCheckout() parallelsAlwaysFailFast() } Also, the stage doing the sparce checkout is running on different node. So full pipe looks like: pipeline { agent { node {label 'node1' } } options { timeout(time: 2, unit: 'HOURS' ) skipDefaultCheckout() } stages { stage( 'Build & Checks' ) { checkout scm ... } stage( 'Smoke Test' ) { agent { node {label 'node2' } } steps { echo( "Running on node: ${NODE_NAME}" ) script { checkout scmGit( branches: [[name: "refs/heads/${env.BRANCH_NAME}" ]], extensions: [ cleanBeforeCheckout(), [ $class: 'SparseCheckoutPaths' , sparseCheckoutPaths: [ [path: 'my_path' ] ] ] ], userRemoteConfigs: [[credentialsId: 'my_cred_id' , url: "my_url" ]] ) } } } } }

          Mark Waite added a comment -

          I can't duplicate it based on your most recent description. I've placed my experiments in the JENKINS-70858 branch of my bug validation repository. I've tried various forms of declarative Pipeline all with the same result, the sparse checkout definition is honored. The Pipeline definition that I used was:

          pipeline {
            options {
              buildDiscarder logRotator(numToKeepStr: '10')
              disableConcurrentBuilds abortPrevious: true
              parallelsAlwaysFailFast()
              skipDefaultCheckout()
            }
            agent none
            stages {
              stage('Non-Windows') {
                agent {
                  label '!windows && !git-1.8' // git 1.8 does not support shallow clone
                }
                steps {
                  checkout scmGit(branches: [[name: 'JENKINS-70858']],
                                  extensions: [cloneOption(honorRefspec: true, noTags: true, shallow: true, depth: 1)],
                                  gitTool: 'Default',
                                  userRemoteConfigs: [[refspec: '+refs/heads/JENKINS-70858:refs/remotes/origin/JENKINS-70858',
                                                       url: 'https://github.com/MarkEWaite/jenkins-bugs.git']])
                  sh 'ls; cat README.md'
                }
              }
              stage('Windows') {
                agent {
                  label 'windows'
                }
                steps {
                  checkout scmGit(branches: [[name: 'JENKINS-70858']],
                                  extensions: [cloneOption(honorRefspec: true, noTags: true, shallow: true, depth: 1),
                                  [$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'build.xml']]]],
                                  gitTool: 'Default',
                                  userRemoteConfigs: [[refspec: '+refs/heads/JENKINS-70858:refs/remotes/origin/JENKINS-70858',
                                                       url: 'https://github.com/MarkEWaite/jenkins-bugs.git']])
                  bat 'dir'
                }
              }
            }
          }
          

          Are you running an older version of command line git on the agent that has the issue? Sparse checkout does not work on command line git 1.8 as included with CentOS 7, Oracle Linux 7, Scientific Linux 7, and other similar operating systems. I recommend at least command line git 2.11 and I prefer command line git 2.40.

          Mark Waite added a comment - I can't duplicate it based on your most recent description. I've placed my experiments in the JENKINS-70858 branch of my bug validation repository . I've tried various forms of declarative Pipeline all with the same result, the sparse checkout definition is honored. The Pipeline definition that I used was: pipeline { options { buildDiscarder logRotator(numToKeepStr: '10') disableConcurrentBuilds abortPrevious: true parallelsAlwaysFailFast() skipDefaultCheckout() } agent none stages { stage('Non-Windows') { agent { label '!windows && !git-1.8' // git 1.8 does not support shallow clone } steps { checkout scmGit(branches: [[name: 'JENKINS-70858']], extensions: [cloneOption(honorRefspec: true, noTags: true, shallow: true, depth: 1)], gitTool: 'Default', userRemoteConfigs: [[refspec: '+refs/heads/JENKINS-70858:refs/remotes/origin/JENKINS-70858', url: 'https://github.com/MarkEWaite/jenkins-bugs.git']]) sh 'ls; cat README.md' } } stage('Windows') { agent { label 'windows' } steps { checkout scmGit(branches: [[name: 'JENKINS-70858']], extensions: [cloneOption(honorRefspec: true, noTags: true, shallow: true, depth: 1), [$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'build.xml']]]], gitTool: 'Default', userRemoteConfigs: [[refspec: '+refs/heads/JENKINS-70858:refs/remotes/origin/JENKINS-70858', url: 'https://github.com/MarkEWaite/jenkins-bugs.git']]) bat 'dir' } } } } Are you running an older version of command line git on the agent that has the issue? Sparse checkout does not work on command line git 1.8 as included with CentOS 7, Oracle Linux 7, Scientific Linux 7, and other similar operating systems. I recommend at least command line git 2.11 and I prefer command line git 2.40.

          Mark Waite added a comment -

          Closing after several weeks with no response. Cannot duplicate

          Mark Waite added a comment - Closing after several weeks with no response. Cannot duplicate

            Unassigned Unassigned
            eugenskt Eugen Kleinschmidt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: