Jenkins配置gitlab Credentials

2024-01-09  本文已影响0人  87d6dc4b11a7

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

image.png

使用HTTPHTTPS协议

使用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拷贝到代理节点。

上一篇 下一篇

猜你喜欢

热点阅读