You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins停用6个月后Git克隆失败,凭据ID方式失效求助

问题描述

我有一个已稳定运行数年的Jenkins流水线,停用6个月后重新执行时,在git clone阶段失败。

相关信息

  • 使用无期限的GitHub经典令牌
  • 仓库为组织私有仓库
  • 流水线未做任何修改
  • 初始Jenkins版本为2.319.3,Git版本为2.35.1.windows.2

流水线代码

pipeline {
    agent any

    tools {
        maven 'M3'
    }

    stages {
        stage('Clone repository') {
            steps {
                echo 'clone git'
                git (
                    branch: 'main',
                    url: 'https://github.com/<organization>/<repo>',
                    credentialsId: '<credentialsId>'
                )
            }
        }

        stage('Build Maven') {
            // ...
        }

        stage('Build image') {
            // ...
        }

        stage('Push image') {
            // ...
        }
    
        stage('SSH deploy') {
            // ...
        }

        stage('Delete dangling image') {
            // ...
        }
    }
}

控制台错误输出

The recommended git tool is: NONE
using credential <credentialsId>
 > git.exe rev-parse --resolve-git-dir C:\ProgramData\Jenkins\.jenkins\workspace\iot\.git # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url https://github.com/<organization>/<repo> # timeout=10
Fetching upstream changes from https://github.com/<organization>/<repo>
 > git.exe --version # timeout=10
 > git --version # 'git version 2.50.0.windows.1'
using GIT_ASKPASS to set credentials <credentials description>
 > git.exe fetch --tags --force --progress -- https://github.com/<organization>/<repo> +refs/heads/*:refs/remotes/origin/* # timeout=10
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://github.com/<organization>/<repo>
    at PluginClassLoader for git//hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:999)
    at PluginClassLoader for git//hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1240)
    at PluginClassLoader for git//hudson.plugins.git.GitSCM._checkout(GitSCM.java:1311)
    at PluginClassLoader for git//hudson.plugins.git.GitSCM.checkout(GitSCM.java:1278)
    at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:136)
    at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:101)
    at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:88)
    at PluginClassLoader for workflow-step-api//org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:49)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:842)
Caused by: hudson.plugins.git.GitException: Command "git.exe fetch --tags --force --progress -- https://github.com/<organization>/<repo> +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: remote: Repository not found.
fatal: repository 'https://github.com/<organization>/<repo>/' not found

    at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2846)
    at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2191)
    at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:641)
    at PluginClassLoader for git//hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:997)
    ... 12 more
ERROR: Error fetching remote repo 'origin'
ERROR: Maximum checkout retry attempts reached, aborting

已尝试的操作

  • 升级Jenkins至2.504.3版本
  • 升级Git至2.50.0.windows.1版本
  • 更新Jenkins插件
  • 升级Java至17版本
  • 尝试新的经典令牌和细粒度令牌(均失败)

注:细粒度令牌直接嵌入流水线URL可正常克隆,说明令牌本身有效

可能的原因
  • Jenkins凭证配置异常:凭证ID匹配,但存储的实际凭证可能损坏、误删或配置错误(比如GitHub令牌需填在密码字段,若错误填入用户名字段会导致认证失败,GitHub会返回仓库不存在的误导性提示)。
  • Git客户端凭证缓存冲突:Jenkins代理节点的Git缓存了旧的无效凭证,导致新凭证无法生效。可清理代理节点的Git凭证缓存(比如Windows凭据管理器中的GitHub条目,或Git的credential.helper缓存)。
  • 组织仓库权限变更:令牌本身有效,但对应账号被移除仓库访问权限,或组织开启IP白名单后Jenkins服务器IP不在列表内,此时GitHub会返回仓库不存在的错误。
  • Git插件与版本兼容性问题:升级后的Git插件与Git客户端存在兼容性冲突,导致凭证传递失败。可尝试回退Git插件至旧版本,或调整Git客户端配置(如禁用GIT_ASKPASS)。
  • URL格式问题:错误输出中URL末尾多了斜杠(https://github.com/<organization>/<repo>/),可能是Jenkins处理时自动添加,导致仓库识别错误。可修改流水线中URL为不带末尾斜杠的形式。
  • 网络或代理问题:Jenkins服务器网络环境变更(如新增代理),导致Git请求无法正常到达GitHub,或代理配置错误导致认证信息无法正确传递。

内容的提问来源于stack exchange,提问作者777

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 18:52:41