配置 jenkins 流水线时,需要从远程仓库拉取代码,因此需要在 jenkins 所在机器上创建全局凭证。

1. git 创建公钥和私钥

# 配置名称和邮箱
git config --global user.name "UserName"
git config --global user.email "UserEmail@xxx.com"

# 生成钥匙
ssh-keygen

# 进入目录
cd ~/.ssh

~/.ssh 目录下,查看公钥和私钥,公钥名称一般为 id_rsa.pub,私钥为 id_rsa。

2. jenkins 添加凭证

进入 Jenkins -> Dashboard -> Manage Jenkins -> Credentials,选择添加 Add credentials。

类型选择 SSH Username with private key -> Enter directly -> Add,将私钥粘贴。(注意私钥前后不能留段落或空格)

注意,公钥 id_rsa.pub 需要添加至 GitLab 上。

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐