Centos jenkins编译maven项目时,不能下载pom.xml里面的插件

今天遇到了一个很奇怪的问题,jenkins编译maven项目时,不能下载pom.xml里面的插件,下面是jenkins控制台输出的错误信息。

<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f /var/lib/jenkins/workspace/scm-tomcat/pom.xml -s /app/apache-maven-3.6.0/conf/settings.xml -gs /app/apache-maven-3.6.0/conf/settings.xml clean install
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< com.gwm.tomcat:scm-tomcat >----------------------
[INFO] Building scm-tomcat 0.0.1-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO] Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom
[WARNING] Failed to create parent directories for tracking file /app/local/repository/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom.lastUpdated
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.056 s
[INFO] Finished at: 2019-03-22T16:35:31+08:00
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
**[ERROR] Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.6: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from/to alimaven (http://maven.aliyun.com/nexus/content/groups/public): /app/local/repository/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom.part.lock (No such file or directory) -> [Help 1]
[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/PluginResolutionException**
[JENKINS] Archiving /var/lib/jenkins/workspace/scm-tomcat/pom.xml to com.gwm.tomcat/scm-tomcat/0.0.1-SNAPSHOT/scm-tomcat-0.0.1-SNAPSHOT.pom
channel stopped
Finished: FAILURE

解决思路:

1.确定jenkins服务器可以访问http://maven.aliyun.com/nexus/content/groups/public,

在服务器上输入以下命令:

wget http://maven.aliyun.com/nexus/content/groups/public
在这里插入图片描述
虽然报404,但是你可以在浏览器上查看,显示"不影响构建"
在这里插入图片描述
所以,不是网址不能访问导致的插件下载失败。

2.确定是org.apache.maven.plugins:maven-resources-plugin插件不能下载,还是全部的插件都下载失败

在服务器上打开本地的仓库,即在maven的settin.xml文件中配置的地址

 [root@cicd conf]# vim /app/maven/conf/settings.xml

在这里插入图片描述
发现/app/local/repository目录下,为空,即全部的插件都下载失败。
在这里插入图片描述
3.排查jenkins环境的问题

在项目的存放目录,执行mvn clean install,查看插件是否可以下载

[root@cicd ~]# cd /var/lib/jenkins/workspace/scm-tomcat/
[root@cicd scm-tomcat]# mvn clean 

在这里插入图片描述
发现插件下载成功

4.综上所述,是jenkins配置的问题

又反复查看了报错信息,发现警告信息,很有价值
在这里插入图片描述
应该是jenkins的启动用户没有权限对"/app/local/repository"执行"写"的操作

打开jenkins的配置文件,一般是/etc/sysconfig/jenkins
在这里插入图片描述
发现,jenkins的启动用户是jenkins,你一定很好奇,没有创建过jenkins用户啊,那是因为在jenkins的时候,系统自动创建了名为jenkins的

用户和用户组,可以使用以下命令查询

#是否存在用户组:jenkins
[root@cicd ~]# cat /etc/group|grep jenkins
#是否存在用户:jenkins
[root@cicd ~]# cat /etc/passwd|grep jenkins
#查看用户jenkins的用户组
[root@cicd ~]# groups jenkins

在这里插入图片描述
接下来,我们尝试修改/app/local/repository的用户组和用户

[root@cicd local]# chown -R jenkins:jenkins repository
修改权限
[root@cicd local]# chmod -R g-w repository
[root@cicd local]# chmod -R o-wx repository

在jenkins上构建,发现构建成功,问题解决在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43840640/article/details/88747144
今日推荐