k8s + docker + Jenkins使用Pipeline部署SpringBoot项目时Jenkins错误集锦
背景
- 系统版本: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/archives/article/1805
k8s + docker + Jenkins使用Pipeline部署SpringBoot项目时Jenkins错误集锦的更多相关文章
- Docker快速上手之部署SpringBoot项目
Docker是基于Go语言实现的云开源项目. Docker的主要目标是“Build,Ship and Run Any App,Anywhere”,也就是通过对应用组件的封装.分发.部署.运行等生命周期 ...
- 部署springboot项目时 打包成jar时包中html,js,css文件缺失
问题 打包出来的jar包里面没有html,js,css文件 解决方案 在pom.xml文件下的build选项中的src/main/resources的目录下 添加配置 <build> &l ...
- maven部署tomcat项目,403错误解决
maven部署tomcat项目时403错误的解决方法 web模块的pom文件 pom.xml <plugin> <groupId>org.apache.tomcat.maven ...
- docker部署springboot项目
本文介绍一下docker如何部署springboot项目. 前提条件: 1.可以运行jar包的环境 2.机器上已经安装了docker 3.准备部署的springboot的jar包 4.Dockerfi ...
- mac和linux下使用Docker,部署SpringBoot项目到docker
主要是看一下如何在linux及mac上安装docker,创建docker镜像,部署SpringBoot项目到docker,并借助于DaoCloud进行docker镜像下载加速等. 我用的电脑是mac, ...
- Docker下部署springboot项目
1.背景 如何在docker容器环境下部署一个springboot项目? 2.具体步骤 第一步:准备一个springboot项目的xxxx.jar包 jar包中用于测试的一个接口如下 第二步:编写Do ...
- Jenkins部署springboot项目
记录jenkins如何部署springboot项目(jar类型的) 一.首先需要先配置好jenkins的基本配置(jdk.maven--),可在系统管理-->>全局工具配置中进行配置. 配 ...
- 利用Dockerfile部署SpringBoot项目
利用Dockerfile部署SpringBoot项目 1.创建一个SpringBooot项目并且打成jar包 2.在Linux中创建一个文件夹,来做docker测试 [root@izwz90lvzs7 ...
- 使用Cloud Toolkit部署SpringBoot项目到服务器
由于我们经常发布项目到测试服,在测试服上调试一些本地无法调试的东西,所以出现了各种打包,然后上传.启动,时间都耗费在这无聊的事情上面了,偶然在网上看到IntelliJ IDEA有 Cloud Tool ...
随机推荐
- 3,Java中的文件IO流
1,File类 ··· 概念:File对象可以表示一个文件或目录.可以对其进行增删改查. ··· 常用方法: File f = new File("."); 判断是 ...
- Access Token 机制详解
我们在访问很多大公司的开放 api 的时候,都会发现这些 api 要求传递一个 access token 参数.这个参数是什么呢?需要去哪里获取这个 access token 呢? access to ...
- 使用Navicat Premiun远程连接MySQL失败,报错(10038)
远程连接MySQL失败,可能有一下原因: 1.小伙子/小姑凉注意一下你的ip是否输入正确了!! 2.网络或防火墙问题 1).排查网络问题 使用命令:ping 192.168.1.1 查看网络请求是否超 ...
- 第三篇:Linux的基本操作与文件管理(纯命令行模式下)(下)
接上篇介绍完软件的管理(查询.删除.安装)之后,本篇将介绍Linux的文件和目录的管理. 如何浏览Linux的目录(文件夹),就像Windows一样,我们平时需要打开各个目录,去里面找一找曾经悄悄存储 ...
- MATLAB神经网络(1) BP神经网络的数据分类——语音特征信号分类
1.1 案例背景 1.1.1 BP神经网络概述 BP神经网络是一种多层前馈神经网络,该网络的主要特点是信号前向传递,误差反向传播.在前向传递中,输入信号从输入层经隐含层逐层处理,直至输出层.每一层的神 ...
- Ubuntu 18 安装 cuda 10
1.把预先下好的cuda放到某个目录,如Download. 2.Crtl + Alt + F3 进入tty,使用tty登录. 关闭用户图形界面,sudo systemctl set-default m ...
- 详解如何快速使用数据可视化BI软件创建医疗运营监控数据中心大屏
灯果数据可视化BI软件是新一代人工智能数据可视化大屏软件,内置丰富的大屏模板,可视化编辑操作,无需任何经验就可以创建属于你自己的大屏.大家可以在他们的官网下载软件. 本文以医疗运营监控数据中心大屏 ...
- Google Sign In
我们平常也经常使用QQ,微信账号,登录其他应用.最近公司让我给网站添加一个谷歌账号登录.我来这里记录一下,莫怪~~~莫怪~~~ 1. 申请一个账号登录ID: https://developers.g ...
- 【TIJ4】第三章全部习题
题目都相当简单没啥说的直接放代码就行了... 3.1 package ex0301; //[3.1]使用“简短的”和正常的打印语句来写一个程序 import static java.lang.Syst ...
- EF Core-1
带着问题去思考,大家好! 前几天了解到EF Core的开发模式:DB First(数据库优先),Model First(模式优先),Code First(代码优先). 我所接触的大多是DB First ...