李锋镝的博客

  • 首页
  • 时间轴
  • 说说
  • 每日心情
  • Now
  • 系列文章
  • 论坛
  • 左邻右舍
    • 左邻右舍
    • 博友圈
  • 留言
    • 留言
    • 走心评论
  • 关于
    • 关于我
    • 网站地图
    • 网站统计
    • 另一个网站
    • 我的导航站
    • 赞助
  • 🚇开往
Destiny
自是人生长恨水长东
  1. 首页
  2. 代码人生
  3. 正文

k8s + docker + Jenkins使用Pipeline部署SpringBoot项目时Jenkins错误集锦

2020年4月8日 约 1,209 字5 分钟 38 0 0
本文最后更新于 2025年11月20日,距今已 267 天,其中的信息可能已经发生变化,请注意甄别。

背景

  • 系统版本:CentOS7
  • Jenkins版本:2.222.1
  • maven版本:apache-maven-3.6.3
  • Java版本:jdk1.8.0_231
  • Git版本:1.8.3.1
  • docker版本:1.13.1
  • k8s版本:1.9.8

使用yum install jenkins方式安装jenkins。

俺的Jenkins只部署了一台机器。

错误1

使用git branch: "$brans", credentialsId: 'platform-jenkins', url: "$GIT_URL/${app_name}.git"下载代码时提示以下异常,但是在服务器上执行git clone命令却能正常执行。

ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --progress git@git/kd-gateway.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

错误原因

因为使用的是yum方式安装的Jenkins,所以Jenkins启动的时候启动用户是jenkins(可以通过ps -ef|grep jenkins来查看启动用户),而Jenkins服务器上ssh的相关配置和用户却是root,所以就导致没有权限去执行git命令。

解决办法

配置git账号的ssh免密登录,具体怎么配置可以自行百度,这里说下配置的时候需要注意的点:

  • 生成的对应的公钥、私钥的位置是在/var/lib/jenkins/.ssh目录下
  • 确认id_rsa、id_rsa.pub这两个文件的所属用户、用户组都是jenkins
  • git网站中需要给对应账号配置ssh key
    [root@infra2-test-k8s .ssh]# ls -l
    total 12
    -rw-------. 1 jenkins jenkins 1679 Apr  7 20:50 id_rsa
    -rw-r--r--. 1 jenkins jenkins  393 Apr  7 20:50 id_rsa.pub
    -rw-r--r--. 1 jenkins jenkins  197 Apr  7 19:19 known_hosts

    修改文件所属用户、用户组命令:chown -R jenkins:jenkins id_rsa。

然后去掉拉取git代码的命令行中的credentialsId:git branch: "$brans", url: "$GIT_URL/${app_name}.git

还有另外一种就是修改jenkins用户的用户组,将其放入root用户组中,命令如下:

# 添加
gpasswd -a root jenkins

# 移除
gpasswd -d root jenkins

jenkins启动用户是放在/etc/sysconfig/jenkins文件中的JENKINS_USER参数下,对应的用户组参数:JENKINS_GROUP

这个办法理论上是可以的,不过我没试,这里仅供参考。

错误2

ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from git@git/kd-gateway.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:909)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1131)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1167)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:124)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:93)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: hudson.plugins.git.GitException: Command "git config remote.origin.url git@git/kd-gateway.git" returned status code 255:
stdout: 
stderr: error: could not lock config file .git/config: Permission denied

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2430)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2360)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2356)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1916)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1928)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.setRemoteUrl(CliGitAPIImpl.java:1542)
    at hudson.plugins.git.GitAPI.setRemoteUrl(GitAPI.java:160)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:897)
    ... 11 more

错误原因就是没有配置git的ssh免密登录权限,在服务器上配置下即可。

错误3

使用maven命令打包时提示:

+ mvn -Dmaven.test.failure.ignore clean package -P test
which: no java in (/sbin:/usr/sbin:/bin:/usr/bin)
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

但是去服务器上看了下Java的配置没问题,maven的配置也没问题,PATH也没问题。

原因

maven是从/sbin:/usr/sbin:/bin:/usr/bin这几个目录下找Java的,去服务器上的这几个目录下看了,确实没有Java,那么原因应该就是这个了。

解决办法

做个Java的软连接即可。
命令:

ln -s JAVA_HOME/bin/java /usr/bin/java

错误4

+ mvn -Dmaven.test.failure.ignore clean package -P test
[INFO] Scanning for projects...
Downloading from nexus: http://XXXX:8081/repository/maven-public/org/springframework/boot/spring-boot-starter-parent/2.2.5.RELEASE/spring-boot-starter-parent-2.2.5.RELEASE.pom
[WARNING] Failed to create parent directories for tracking file /opt/apache-maven-3.6.3/LocalRepo/org/springframework/boot/spring-boot-starter-parent/2.2.5.RELEASE/spring-boot-starter-parent-2.2.5.RELEASE.pom.lastUpdated
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for cn.kuaidao:gateway:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.5.RELEASE from/to nexus (http://XXXX:8081/repository/maven-public/): /opt/apache-maven-3.6.3/LocalRepo/org/springframework/boot/spring-boot-starter-parent/2.2.5.RELEASE/spring-boot-starter-parent-2.2.5.RELEASE.pom.part.lock (No such file or directory) and 'parent.relativePath' points at no local POM @ line 5, column 13
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project cn.kuaidao:gateway:0.0.1-SNAPSHOT (/var/lib/jenkins/workspace/test-kd-gateway/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for cn.kuaidao:gateway:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.5.RELEASE from/to nexus (http://XXXX:8081/repository/maven-public/): /opt/apache-maven-3.6.3/LocalRepo/org/springframework/boot/spring-boot-starter-parent/2.2.5.RELEASE/spring-boot-starter-parent-2.2.5.RELEASE.pom.part.lock (No such file or directory) and 'parent.relativePath' points at no local POM @ line 5, column 13 -> [Help 2]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

错误原因

原因和错误1一样,都是用户权限的问题,jenkins用户没有权限去LocalRepo这个目录下创建文件、文件夹,所以就导致找不到文件。ls -l命令查看/opt/apache-maven-3.6.3/LocalRepo这个文件夹所属用户和用户组都是root,修改为jenkins即可。

解决办法

修改文件夹所属用户、用户组。
命令:chown -R jenkins:jenkins LocalRepo。

错误5

使用docker构建应用提示以下错误:

+ docker build -t 192.168.30.176:5000/kd-gateway:1.0.29-test -f docker/Dockerfile .
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.26/build?buildargs=%7B%7D&buildbinds=null&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=docker%2FDockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=192.168.30.176%3A5000%2Fkd-gateway%3A1.0.29-test&ulimits=null: dial unix /var/run/docker.sock: connect: permission denied

错误原因

/var/run/docker.sock权限问题,这个文件的所属用户、用户组都是root,需要将其修改为jenkins用户。

解决办法

修改文件所属用户、用户组。
命令:chown -R jenkins:jenkins docker.sock。

总结

大部分都是权限问题,但是不知道什么原因,我的root用户切换不了jenkins用户,导致排查问题只能靠我机智的大脑去猜,这个就很坑。

除非注明,否则均为李锋镝的博客原创文章,转载必须以链接形式标明本文链接

本文链接:https://www.lifengdi.com/dai-ma-ren-sheng/1805

推荐阅读

  • k8s+docker部署Golang项目
  • Java开发的ACK+Jenkins一键部署迁移实战
  • 属性名称闹的一场乌龙事件
  • SpringBoot 实现接口防刷的 5 种实现方案
  • 解决kubectl exec -it xxxx-service-bfbd45bb9-ktvzj bash -n bit error: exec [POD] [COMMAND] is not supported anymore. Use exec [POD] -- [COMMAND] instead See 'kubectl exec -h' for help and examples
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可
标签: docker Jenkins K8s SpringBoot 分布式
最后更新:2025年11月20日

岁月同一天 8 月 15 日

回望过去的今天,你在写什么

  • 7 年前 2019年8月15日
    【三国轶闻】张飞多次挑衅吕布却安然无事,吕布到底害怕张飞什么?

    说起三国第一猛将,当属吕布吕奉先了。 吕布有多猛?这个自己说了不算,都是别人给他衬托出来的。比较经典的事件,第一个就是三…

  • 7 年前 2019年8月15日
    终于有人把Elasticsearch原理讲透了!

    小史是一个非科班的程序员,虽然学的是电子专业,但是通过自己的努力成功通过了面试,现在要开始迎接新生活了。 随着央视诗词大…

  • 7 年前 2019年8月15日
    HTTP和HTTPS协议

    大纲 一、前言: 先来观察这两张图,第一张访问域名http://www.12306.cn,谷歌浏览器提示不安全链接,第二…

相关文章
  • 分布式服务生成唯一不重复ID(24位字符串)2019年7月13日
  • 从零搭建Spring Cloud Gateway网关(一)2020年3月18日
  • Redis的主从同步及Redis Cluster(集群)下的高可用2021年4月16日
  • SpringBoot使用RestTemplate进行接口调用2021年1月19日
  • 从零开始入门 K8s | 手把手带你理解 etcd2020年5月16日

李锋镝

既然选择了远方,便只顾风雨兼程。

打赏 点赞
< 上一篇
下一篇 >
1234567891112131415161718192021222324252627282930313233343536373839404142434446474849505152535455575859606162636465666769727476777879808182858687909293949596979899
取消回复

文章评论

还没有评论,快来抢沙发吧~

The pessimist complains about the wind; the optimist expects it to change; the realist adjusts the sails.

听点儿音乐吧 朋友~
文章目录
最新 热点 随机
最新 热点 随机
每日早报 · 2026年8月15日 每日早报 · 2026年8月14日 Chrome 浏览器漏洞 Aeron详解 Kratos+ v1.1.16版本更新说明 WorkBuddy介绍
给主题增加了Now、每日心情、年度回顾、岁月同一天、随机漫步等功能AI时代,个人技术博客的出路在哪里?Kratos+ v1.1.16版本更新说明增加了两套复古皮肤-牛皮纸、千禧网页这个域名注册整整十年了,十年时间,真快啊Kratos+ v1.1.14版本更新说明
Wails 深度实战指南:用 Go + 前端技术打造轻量桌面应用(从入门到部署) 更多的Xshell配色方案 AI 协作新范式:以文档为中心的开发实践指南 Java并发编程之如何保证线程顺序执行 还不懂Redis?看完这个故事就明白了! 提示词工程进阶指南:8大核心技巧,让AI精准读懂你的需求(2025实战版)
最近评论
S.MBA 发布于 9 小时前(08月14日) 最喜欢友链增强里那套:链接探活能及时发现失效友站,自助申请表单+后台一键审核,还有博友圈用RSS自动...
李锋镝 发布于 16 小时前(08月14日) 风凉那日,便是秋来。
李锋镝 发布于 16 小时前(08月14日) 听说评论速度现在快的飞起~ :40:
李锋镝 发布于 19 小时前(08月14日) 你的那个主题也很棒,我这里还有功能参考了你的主题的~
满心 发布于 22 小时前(08月14日) 都是实用功能,赞
标签聚合
ElasticSearch JAVA AI编程 分布式 设计模式 日常 WordPress Claude K8s MySQL AI 数据库 SQL JVM 多线程 Redis Spring SpringBoot IDEA 架构
友情链接
  • Blogs·CN

COPYRIGHT © 2026 lifengdi.com. ALL RIGHTS RESERVED.

正在博友圈履约中

域名年龄

Theme Kratos+ By Dylan Li

津ICP备2024022503号-3

京公网安备11011502039375号