Kenkins拉取GitLab代码

news/2024/12/16 12:30:01/文章来源:https://www.cnblogs.com/shiqiang-lee/p/18609804

Jenkins从GitLab中拉取代码

1.在Jenkins主机上生成ssh密钥

[root@jenkins gitrepo]# ssh-keygen -t ed25519
Generating public/private ed25519 key pair.
Enter file in which to save the key (/root/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_ed25519
Your public key has been saved in /root/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:OQNieyyrapJQqjjg6+yeQmqV/E6lAB6WGTlQ+TNqBBM root@jenkins
The key's randomart image is:
+--[ED25519 256]--+
|E+o.             |
|oo=              |
| O..o .          |
|o =.++ . .       |
| =.o+oo.S        |
|+.o+.+o  o       |
|Oo. oo           |
|X+....           |
|XXo ..           |
+----[SHA256]-----+
[root@jenkins gitrepo]# ls -al  ~/.ssh/
total 12
drwx------. 2 root root   46 Dec 15 22:23 .
dr-xr-x---. 7 root root 4096 Dec 15 21:49 ..
-rw-------  1 root root  399 Dec 15 22:23 id_ed25519
-rw-r--r--  1 root root   94 Dec 15 22:23 id_ed25519.pub
[root@jenkins gitrepo]# cat  ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDU5uZvN6i7fuEjWNST02lISBuVloc6y+sIYSycs0GUq root@jenkins

2.在GitLab中配置公钥

点击“头像”,选择“编辑个人资料”

点击“SSH密钥”

复制jenkins主机上生成的公钥

[root@jenkins gitrepo]# cat  ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDU5uZvN6i7fuEjWNST02lISBuVloc6y+sIYSycs0GUq root@jenkins
[root@jenkins gitrepo]# ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDU5uZvN6i7fuEjWNST02lISBuVloc6y+sIYSycs0GUq root@jenkinszzzhan

粘贴SSH密钥

4. kenkins添加凭证

点击用户名=》点击“凭证”

复制私钥

[root@jenkins gitrepo]# cat  ~/.ssh/id_ed25519
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACA1Obmbzeou37hI1jUk9NpSEgblZaHOsvrCGEsnLNBlKgAAAJBFzLPDRcyz
wwAAAAtzc2gtZWQyNTUxOQAAACA1Obmbzeou37hI1jUk9NpSEgblZaHOsvrCGEsnLNBlKg
AAAEA24KdkDfuk5oxflDyXmK9cI2tdOR5g8UZZHEj+CXvHEzU5uZvN6i7fuEjWNST02lIS
BuVloc6y+sIYSycs0GUqAAAADHJvb3RAamVua2lucwE=
-----END OPENSSH PRIVATE KEY-----

点击“Create”

往下滑,找到“Git Host Key Verification Configuration”选择“Accept first connection”,必须选择否则构建会报错

点击项目的“配置”

粘贴仓库的地址,然后选择刚刚配置的凭证

构建项目,显示构建成功

Established TCP socket on 33209
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -N -B -f /var/lib/jenkins/workspace/maven-docker/pom.xml clean package -Dmaven.test.skip=true
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for springmvc-maven:easy-springmvc-maven:war:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-war-plugin is missing. @ line 22, column 15
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] ----------------< springmvc-maven:easy-springmvc-maven >----------------
[INFO] Building springmvc-maven 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ war ]---------------------------------
[WARNING] Parameter 'version' is unknown for plugin 'maven-war-plugin:3.4.0:war (default-war)'
[INFO] 
[INFO] --- clean:3.2.0:clean (default-clean) @ easy-springmvc-maven ---
[INFO] Deleting /var/lib/jenkins/workspace/maven-docker/target
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ easy-springmvc-maven ---
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/maven-docker/src/main/resources
[INFO] 
[INFO] --- compiler:3.1:compile (default-compile) @ easy-springmvc-maven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /var/lib/jenkins/workspace/maven-docker/target/classes
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ easy-springmvc-maven ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- compiler:3.1:testCompile (default-testCompile) @ easy-springmvc-maven ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- surefire:3.2.5:test (default-test) @ easy-springmvc-maven ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- war:3.4.0:war (default-war) @ easy-springmvc-maven ---
[INFO] Packaging webapp
[INFO] Assembling webapp [easy-springmvc-maven] in [/var/lib/jenkins/workspace/maven-docker/target/easy-springmvc-maven]
[INFO] Processing war project
[INFO] Copying webapp resources [/var/lib/jenkins/workspace/maven-docker/src/main/webapp]
[INFO] Building war: /var/lib/jenkins/workspace/maven-docker/target/easy-springmvc-maven.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  7.918 s
[INFO] Finished at: 2024-12-15T23:05:12-05:00
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /var/lib/jenkins/workspace/maven-docker/pom.xml to springmvc-maven/easy-springmvc-maven/0.0.1-SNAPSHOT/easy-springmvc-maven-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /var/lib/jenkins/workspace/maven-docker/target/easy-springmvc-maven.war to springmvc-maven/easy-springmvc-maven/0.0.1-SNAPSHOT/easy-springmvc-maven-0.0.1-SNAPSHOT.war
Finished: SUCCESS

5. 其他

5.1 报错“stderr: No ED25519 host key is known for 192.168.100.31 and you have requested strict checking”

Started by user roy li
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/maven-docker
The recommended git tool is: NONE
using credential 3> git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/maven-docker/.git # timeout=10
Fetching changes from the remote Git repository> git config remote.origin.url git@192.168.100.31:plat-group/easy-springmvc-maven.git # timeout=10
Fetching upstream changes from git@192.168.100.31:plat-group/easy-springmvc-maven.git> git --version # timeout=10> git --version # 'git version 2.43.5'
using GIT_SSH to set credentials Roy's GitLab credentials
[INFO] SELinux is present on the host and we could not confirm that it does not apply actively: will try to relabel temporary files now; this may complain if context labeling not applicable after all> /usr/bin/chcon --type=ssh_home_t /var/lib/jenkins/workspace/maven-docker@tmp/jenkins-gitclient-ssh556435468242475846.key
Verifying host key using known hosts file
You're using 'Known hosts file' strategy to verify ssh host keys, but your known_hosts file does not exist, please go to 'Manage Jenkins' -> 'Security' -> 'Git Host Key Verification Configuration' and configure host key verification.> git fetch --tags --force --progress -- git@192.168.100.31:plat-group/easy-springmvc-maven.git +refs/heads/*:refs/remotes/origin/* # timeout=10
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from git@192.168.100.31:plat-group/easy-springmvc-maven.gitat PluginClassLoader for git//hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:997)at PluginClassLoader for git//hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1239)at PluginClassLoader for git//hudson.plugins.git.GitSCM._checkout(GitSCM.java:1310)at PluginClassLoader for git//hudson.plugins.git.GitSCM.checkout(GitSCM.java:1277)at hudson.scm.SCM.checkout(SCM.java:540)at hudson.model.AbstractProject.checkout(AbstractProject.java:1250)at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:649)at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85)at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:522)at hudson.model.Run.execute(Run.java:1833)at PluginClassLoader for maven-plugin//hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)at hudson.model.ResourceController.execute(ResourceController.java:101)at hudson.model.Executor.run(Executor.java:446)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- git@192.168.100.31:plat-group/easy-springmvc-maven.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: No ED25519 host key is known for 192.168.100.31 and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.Please make sure you have the correct access rights
and the repository exists.at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2848)at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2184)at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:635)at PluginClassLoader for git//hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:995)... 12 more
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE

解决,找到“系统管理”=》“全局安全设置”=》“Git Host Key Verification Configuration”=》选择“Accept first connection”

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/853725.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Kenkins拉取GitLab代码 - 副本

Jenkins、GitLab、Jenkins拉取GitLab代码Jenkins从GitLab中拉取代码 1.在Jenkins主机上生成ssh密钥 [root@jenkins gitrepo]# ssh-keygen -t ed25519 Generating public/private ed25519 key pair. Enter file in which to save the key (/root/.ssh/id_ed25519): Enter passph…

2024《毒液3》最后一舞 Venom: The Last Dance 【内封简英双语字幕】电影百度云/夸克迅雷UC网盘资源链接下载

导演凯莉马塞尔 主演汤姆哈迪 / 切瓦特埃加福 / 朱诺坦普尔 / 瑞斯伊凡斯 / 斯蒂芬格拉汉姆 / 佩吉陆 / 安迪瑟金斯 / 克拉克巴茨科 / 阿兰娜乌巴赫 / 克里斯托费尔南德斯 / 杰瑞德亚伯拉汉姆森 / 哈拉芬利 / 达什麦克劳德 / 瑞德斯科特 / 杰克布雷迪 / 伊沃南迪 / 杰克阿林 / …

2024《毒液3》最后一舞 Venom: The Last Dance 【内封简英双语字幕】电影(含网盘链接)

导演凯莉马塞尔 主演汤姆哈迪 / 切瓦特埃加福 / 朱诺坦普尔 / 瑞斯伊凡斯 / 斯蒂芬格拉汉姆 / 佩吉陆 / 安迪瑟金斯 / 克拉克巴茨科 / 阿兰娜乌巴赫 / 克里斯托费尔南德斯 / 杰瑞德亚伯拉汉姆森 / 哈拉芬利 / 达什麦克劳德 / 瑞德斯科特 / 杰克布雷迪 / 伊沃南迪 / 杰克阿林 / …

如何计算多分类情况下的敏感性指标

1. 混淆矩阵cm,其中矩阵元素 cm[i][j] 表示真实标签为第 i 类且被预测为第 j 类的样本个数。 2. TP, TN, FP, FN(以类II为例)TP: 实际为正,预测为正(最中间这一格)FN:实际为真,预测为假(中间这一排里面,挖去中间一格,剩下的格子)FP:实际为假,预测为真(中间这一列…

巴黎之旅的美好回忆

ssssss在巴黎的日子里,我们经历了许多难忘的事情...

Odoo外贸定制类(衣服)解决方案

业务背景 客户业务属于定制化外贸服装,通常由他的客户提出定制化产品需求,然后下单给工厂进行生产,工厂生产完成后发货交付。期间由跟单进行发货时间的安排,尾款的跟进和售后服务等等。本例由Odoo16.0协助完成。 SKU设计 由于客户的业务特点更偏向于按需生产,实际业务中客…

语雀使用

方式1安装vscode插件新建.lake后缀的文件语雀导出的文件后缀为.lakebook,不能直接使用该插件进行编辑,需右键解压解压后为lake文件就可以进行编辑了,更多操作方式二将lakebook文件转为markdown方便查看,但lakebook文件中包含思维导图,转为markdown文件时不能显示拉取项目到…

zabbix 5 添加 ICMP PING 监控

目录克隆原生模板修改监控项添加图形添加主机检查结果 克隆原生模板改名字,添加成新模板修改监控项修改每个监控项的键值,追加: [{HOSTNAME}]添加图形添加主机添加测试主机(一个通,一个不通)链接模板检查结果看图形================# 水平有限 欢迎指正 #===============…

中电金信成为开源风险评估与治理技术实验室软件物料清单(SBOM)工作组成员单位

近期,中电金信成功加入国家工业信息安全发展研究中心开源风险评估与治理技术实验室软件物料清单(SBOM)工作组,成为其成员单位,并同步加入“筑链计划”之中。SBOM是Software Bill of Materials的缩写,中文名为软件物料清单,SBOM不仅提供了软件项目所用组件和依赖项的详细…

掌控复杂跨境项目?在线文档是你的最佳伙伴

打破国界的协作:在线文档如何重塑跨境团队效率 在如今复杂的商业环境中,跨境团队协作已成为许多企业的常态。然而,如何在文化、时差和语言差异中实现无缝对接,成为一大难题。在线文档协作正在以其独特的优势,为企业开启新的高效协作模式。 全球化带来的协作挑战 跨境团队面…

Send_Email:一款轻量化可定制模板的邮件批量发送工具

免责声明 本工具仅供学习、测试及研究使用,严禁用于任何形式的非法或未经授权的用途。如因违规使用导致任何后果,责任自负,请遵守相关法律法规。以下文章来源于薛定谔的安全 ,作者iak3ec Send_Email:一款轻量化可定制模板的邮件批量发送工具 | 可用于攻防钓鱼或其他邮件个…

前端工程化_构建工具和脚手架_学习笔记

本文主要对构建工具和脚手架进行简要介绍,首先明确了构建工具的作用,因为开发和维护的代码和运行时的代码是不一致,需要构建工具来进行转换,而且这个转换是工程级别的转换;然后介绍了主流构建工具 webpack,介绍了 webpack 的入口、开发服务器、文件指纹、css modules以及源…