1. 程式人生 > >0914-Jenkins yum安裝預設jenkins使用者許可權問題 導致maven編譯許可權錯誤 (Permission denied)

0914-Jenkins yum安裝預設jenkins使用者許可權問題 導致maven編譯許可權錯誤 (Permission denied)

問題

jenkins部署專案maven編譯時報錯

Parsing POMs
Failed to transfer Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.0.3.RELEASE from/to AliMaven (http://maven.aliyun.com/nexus/content/groups/public/): /root/mavenRepo/org/springframework/boot/spring-boot-starter-parent/2.0.3.RELEASE/spring-boot-starter-parent-2.0.3.RELEASE.pom.part.lock (Permission denied)
ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.0.3.RELEASE from/to AliMaven (http://maven.aliyun.com/nexus/content/groups/public/): /root/mavenRepo/org/springframework/boot/spring-boot-starter-parent/2.0.3.RELEASE/spring-boot-starter-parent-2.0.3.RELEASE.pom.part.lock (Permission denied) and 'parent.relativePath' points at no local POM @ line 14, column 13

	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:364)
	at hudson.maven.MavenEmbedder.buildProjects(MavenEmbedder.java:361)
	at hudson.maven.MavenEmbedder.readProjects(MavenEmbedder.java:331)
	at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1328)
	at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1125)
	at hudson.FilePath.act(FilePath.java:1077)
	at hudson.FilePath.act(FilePath.java:1060)
	at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.parsePoms(MavenModuleSetBuild.java:986)
	at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:691)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
	at hudson.model.Run.execute(Run.java:1815)
	at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)

分析

相同mvn命令,本地編譯異常,通過jenkins編譯報錯,定位是使用者許可權問題

在shell中新增whoami列印jenkins用的是jenkins使用者

jenkins是通過yum安裝時自動建立的系統使用者(沒有目錄,沒有配置檔案),無法通過su命令切換

要麼改成root或其他使用者,要麼將mvn相關目錄所有者改為jenkins(實測無效,可能時因為jenkins不是普通使用者,無配置)

解決辦法

將jenkins預設使用者改為root或其他

//修改使用者為root或其他
vim /etc/sysconfig/jenkins

 

//重啟jenkins
systemctl restart jenkins

修改後編譯成功!

[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ wechatmeeting ---
[INFO] Installing /var/lib/jenkins/workspace/microHomeSite/target/wechatmeeting-0.0.1-SNAPSHOT.jar to /root/mavenRepo/com/mircoptech/wechatmeeting/0.0.1-SNAPSHOT/wechatmeeting-0.0.1-SNAPSHOT.jar
[INFO] Installing /var/lib/jenkins/workspace/microHomeSite/pom.xml to /root/mavenRepo/com/mircoptech/wechatmeeting/0.0.1-SNAPSHOT/wechatmeeting-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.919s
[INFO] Finished at: Fri Sep 14 17:41:41 CST 2018
[INFO] Final Memory: 38M/465M
[INFO] ------------------------------------------------------------------------