美文网首页
Jenkins配置gitlab Credentials

Jenkins配置gitlab Credentials

作者: 87d6dc4b11a7 | 来源:发表于2024-01-09 10:43 被阅读0次

Gitlab 支持通过http(https)ssh协议下载代码。

image.png

使用HTTPHTTPS协议

  • 当使用HTTPHTTPS协议访问远程存储库时,需要配置用户名/密码凭证
    image.png

使用ssh协议

  • 当使用ssh协议访问远程存储库时,需要配置ssh私钥凭据

1、生成 SSH 密钥对

在 Jenkins 服务器使用ssh-keygen -t rsa 命令生成生成公钥和私钥。

root@xa197:~# docker exec -ti jenkins-master /bin/bash
jenkins@a8f0723111fe:/$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/var/jenkins_home/.ssh/id_rsa):
Created directory '/var/jenkins_home/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/jenkins_home/.ssh/id_rsa
Your public key has been saved in /var/jenkins_home/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:qtKDMK3+m4VwenDd3386bTp7yvkHSlsOBBznFdPj0k8 jenkins@a8f0723111fe
The key's randomart image is:
+---[RSA 3072]----+
|         .... +o |
|          oo . o.|
|           .. o .|
|    . .     .. oE|
| + o . .S  .  ...|
|o B .  .. . o o .|
| = = ..  . o *.. |
|. + =.      =oo=.|
|...=o.       O%..|
+----[SHA256]-----+

2、将公钥添加到使用的 GitLab 账户

3、在 Jenkins UI 添加 Credentials

image.png

4、验证

配置后,提示无法连接仓库:Command "git ls-remote -h -- ssh://git@xxx/xxx/jenkinsfile.git HEAD" returned status code 128

image.png
解决:在Jenkins服务器进入容器执行
jenkins@a8f0723111fe:~/.ssh$ git ls-remote -h -- ssh://git@xxx/xxx/jenkinsfile.git HEAD
The authenticity of host '[xxx]:2222 ([xxx]:2222)' can't be established.
ED25519 key fingerprint is SHA256:DgMRn3/cowMZz6F2EDdxGOyzGIKK1fEGWX/5GMJd1bM.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[xxx]:2222' (ED25519) to the list of known hosts.
jenkins@a8f0723111fe:~/.ssh$

在Jenkins agent代理节点使用时,将master节点生成的.ssh拷贝到代理节点。

相关文章

网友评论

      本文标题:Jenkins配置gitlab Credentials

      本文链接:https://www.haomeiwen.com/subject/sdaondtx.html