Akemi

jenkins流水线与git凭证报错

2025/01/13

这两天在做jenkins流水线,在从节点中构建,但是出现一个奇怪的现象

我的流水线需要拉取多个凭证,对多个git仓库进行操作,但是经常出现A git可以拉取但B git无法拉取的问题

报错信息

stderr: remote: The project you were looking for could not be found or you don’t have permission to view it.
fatal: repository ‘https://xxxx.git/‘ not found

正常情况下git会使用jenkins提供的凭证进行访问,那就不该出现这种问题

出现这种现象只有可能是因为git采用了单一的凭证进行仓库的认证

git凭证助手

是一个git中帮助用户进行git凭证缓存的配置,默认是不配置的(所以每次git pull时都需要手动输入账号密码来进行拉取)

可以在~/.gitconfig中的[credentials]中进行配置

1
2
3
4
5
6
7
8
linux中常见这两种
[credentials]
helper = store
store是直接使用明文在~/.git-credentials中进行记录,并不是很安全
即https://xxx:xxx@git.xxx.com的方式进行记录

helper = cache
在内存中进行缓存,默认存放15分钟

报错原因

如果使用store(cache没试过,可能也有这个问题)

特别是当仓库环境非常复杂时,比如同个仓库下的多个项目使用的是不同的凭证

就会出现jenkins流水线中拉取成功了A git后就一直使用该凭证,导致无法拉取B git

解决方法

关闭凭证助手即可

1
2
git config --global --unset credential.helper
git config --unset --unset credential.helper
CATALOG
  1. 1. git凭证助手