1

我试图使用稀疏结帐选项来减少我的 Jenkins 管道中的结帐大小。它工作了一段时间,然后当我对脚本进行小修改(不在结帐部分)时,我开始收到此错误

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 存储库中有文件夹 LINUX。我在参数中使用提交 ID 8c544c33e438965f97039bceb885940023e20257 在此处输入图像描述

我收到以下错误:

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 git@github.ford.com: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 git@github.ford.com: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

然后我删除了稀疏结帐扩展

詹金斯管道之后:

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: 'git@github.ford.com:FC-MIS/DS_FCNA_GDW.git']]])
          
        }
      }
    }
  }

我仍然收到与稀疏结帐相关的错误

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 git@github.ford.com: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 git@github.ford.com: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

如果我在这里遗漏了什么,请告诉我。谢谢!

4

1 回答 1

1

我还没有弄清楚这种行为的根本原因。但是,我能够通过删除作业并使用相同的脚本创建另一个作业来克服此错误。不确定一些旧运行是否与工作区中的新运行相混淆。

谢谢你们!

于 2020-07-31T22:27:12.850 回答