Arpit
Arpit

Reputation: 87

Sparse checkout leaves no entry on working directory

I was trying to use Sparse checkout option to reduce the size of checkout in my Jenkins Pipeline. It worked for some time and then when I did small modifications to the script (not in the checkout section), I started getting this error

pipeline {
  agent none
    parameters {
      string(name: 'CommitID', defaultValue: '', description: 'This is to take the commitID for checkout')
      choice choices: ['FRST', 'QA', 'PROD'], description: 'Please select the environment to which the package needs to be deployed', name: 'depServer'
  }
  options {
        buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5')
  }
  stages {
    stage('CodePull-Linux') {
      agent {
        node {
          label 'Master'
        }
      }
      steps {
        timestamps() {
            echo "Hello"
          // Checkout code from github incase commitID from the past is given
checkout([$class: 'GitSCM', branches: [[name: "${params.CommitID}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'LINUX']]], [$class: 'CleanBeforeCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'fceddep', url: '<git_url>']]])        
          
        }
      }
    }
  }
}

Git repository has folder LINUX in it. and I am using commit ID 8c544c33e438965f97039bceb885940023e20257 in paramters enter image description here

I get the following error:

Running on Jenkins in /var/jenkins_home/workspace/DEV/INFMD/DS_Deploy_test
[Pipeline] {
[Pipeline] timestamps
[Pipeline] {
[Pipeline] echo
10:46:55  Hello
[Pipeline] checkout
10:46:55  using credential fceddep
10:46:55   > git rev-parse --is-inside-work-tree # timeout=10
10:46:55  Fetching changes from the remote Git repository
10:46:55   > git config remote.origin.url [email protected]:FC-MIS/DS_FCNA_GDW.git # timeout=10
10:46:56  Cleaning workspace
10:46:56   > git rev-parse --verify HEAD # timeout=10
10:46:56  Resetting working tree
10:46:56   > git reset --hard # timeout=10
10:46:56  ERROR: Error fetching remote repo 'origin'
10:46:56  hudson.plugins.git.GitException: Failed to fetch from [email protected]:FC-MIS/DS_FCNA_GDW.git
10:46:56    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:909)
10:46:56    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1131)
10:46:56    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1167)
10:46:56    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:125)
10:46:56    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:93)
10:46:56    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)
10:46:56    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
10:46:56    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
10:46:56    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
10:46:56    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
10:46:56    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
10:46:56    at java.lang.Thread.run(Thread.java:748)
10:46:56  Caused by: hudson.plugins.git.GitException: Command "git reset --hard" returned status code 128:
10:46:56  stdout: 
10:46:56  stderr: error: Sparse checkout leaves no entry on working directory
10:46:56  fatal: Could not reset index file to revision 'HEAD'.
10:46:56  
10:46:56    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2430)
10:46:56    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2360)
10:46:56    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2356)
10:46:56    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1916)
10:46:56    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.reset(CliGitAPIImpl.java:635)
10:46:56    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.clean(CliGitAPIImpl.java:1006)
10:46:56    at hudson.plugins.git.extensions.impl.CleanBeforeCheckout.decorateFetchCommand(CleanBeforeCheckout.java:44)
10:46:56    at hudson.plugins.git.extensions.GitSCMExtension.decorateFetchCommand(GitSCMExtension.java:288)
10:46:56    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:905)
10:46:56    ... 11 more
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE

Then I removed the sparse checkout extension

Jenkins pipeline After:

pipeline {
  agent none
    parameters {
      string(name: 'CommitID', defaultValue: '', description: 'This is to take the commitID for checkout')
      choice choices: ['FRST', 'QA', 'PROD'], description: 'Please select the environment to which the package needs to be deployed', name: 'depServer'
  }
  options {
        buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5')
  }
  stages {
    stage('CodePull-Linux') {
      agent {
        node {
          label 'Master'
        }
      }
      steps {
        timestamps() {
            echo "Hello"
          // Checkout code from github incase commitID from the past is given
checkout([$class: 'GitSCM', branches: [[name: "${params.CommitID}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CleanBeforeCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'fceddep', url: '[email protected]:FC-MIS/DS_FCNA_GDW.git']]])
          
        }
      }
    }
  }

I still get error related to sparse checkout

Running on Jenkins in /var/jenkins_home/workspace/DEV/INFMD/DS_Deploy_test
[Pipeline] {
[Pipeline] timestamps
[Pipeline] {
[Pipeline] echo
11:00:35  Hello
[Pipeline] checkout
11:00:35  using credential fceddep
11:00:35   > git rev-parse --is-inside-work-tree # timeout=10
11:00:35  Fetching changes from the remote Git repository
11:00:35   > git config remote.origin.url [email protected]:FC-MIS/DS_FCNA_GDW.git # timeout=10
11:00:35  Cleaning workspace
11:00:35   > git rev-parse --verify HEAD # timeout=10
11:00:35  Resetting working tree
11:00:35   > git reset --hard # timeout=10
11:00:35  ERROR: Error fetching remote repo 'origin'
11:00:35  hudson.plugins.git.GitException: Failed to fetch from [email protected]:FC-MIS/DS_FCNA_GDW.git
11:00:35    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:909)
11:00:35    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1131)
11:00:35    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1167)
11:00:35    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:125)
11:00:35    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:93)
11:00:35    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)
11:00:35    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
11:00:35    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
11:00:35    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
11:00:35    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
11:00:35    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
11:00:35    at java.lang.Thread.run(Thread.java:748)
11:00:35  Caused by: hudson.plugins.git.GitException: Command "git reset --hard" returned status code 128:
11:00:35  stdout: 
11:00:35  stderr: error: Sparse checkout leaves no entry on working directory
11:00:35  fatal: Could not reset index file to revision 'HEAD'.
11:00:35  
11:00:35    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2430)
11:00:35    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2360)
11:00:35    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2356)
11:00:35    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1916)
11:00:35    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.reset(CliGitAPIImpl.java:635)
11:00:35    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.clean(CliGitAPIImpl.java:1006)
11:00:35    at hudson.plugins.git.extensions.impl.CleanBeforeCheckout.decorateFetchCommand(CleanBeforeCheckout.java:44)
11:00:35    at hudson.plugins.git.extensions.GitSCMExtension.decorateFetchCommand(GitSCMExtension.java:288)
11:00:35    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:905)
11:00:35    ... 11 more
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE

Please let me know if I am missing something here. Thank you!

Upvotes: 1

Views: 1233

Answers (1)

Arpit
Arpit

Reputation: 87

I did not figure out the root cause for this behavior yet. However I was able to get past this error by deleting the job and creating another one with same script. Not sure if some old runs were messing with the new ones in workspace.

Thank you all!

Upvotes: 1

Related Questions