运行 Maven 命令 jenkins 时权限被拒绝

问题描述 投票:0回答:4

我在 jenkins 的 /home/tes/pom.xml 中的 pom.xml 上运行 maven

clean test
时遇到权限被拒绝的问题。有什么建议

Building in workspace /var/lib/jenkins/workspace/jenkins
[jenkins] $ /usr/share/maven/bin/mvn -f /home/tes/pom.xml clean test
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project  (/home/tes/pom.xml) has 1 error
[ERROR]     Non-readable POM /home/tes/pom.xml: /home/tes/pom.xml (Permission denied)
[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
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE
jenkins permission-denied
4个回答
2
投票

只需授予所有人对 pom.xml 文件的读取权限:

chmod +r /home/tes/pom.xml

1
投票

就我而言,原因是我没有JDK,而只是在全局工具配置> JDK > JDK安装的JAVA_HOME中配置了JRE。事实上,Jenkins 警告您该路径未指向包含 JDK 的内容。

JDK 是某些插件所必需的,例如 Maven Integration 或 Docker Pipeline,如 Jenkins 文档中的 Java 要求 部分所述。所以必须检查这一点,因为它会令人惊讶地导致奇怪的错误:

> git rev-parse refs/remotes/origin/celsus_0-1-0^{commit} # timeout=10
Checking out Revision 0c533cf2327a416a254afa2348abafe7790ba67f (refs/remotes/origin/celsus_0-1-0)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 0c533cf2327a416a254afa2348abafe7790ba67f # timeout=10
Commit message: "first embrio of container image"
 > git rev-list --no-walk 0c533cf2327a416a254afa2348abafe7790ba67f # timeout=10
Parsing POMs
Established TCP socket on 40251
[build] $ /usr/lib/jvm/bin/java -cp /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-agent-1.13.jar:/usr/share/maven/boot/plexus-classworlds-2.x.jar:/usr/share/maven/conf/logging jenkins.maven3.agent.Maven35Main /usr/share/maven /var/cache/jenkins/war/WEB-INF/lib/remoting-4.5.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-interceptor-1.13.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.13.jar 40251
ERROR: Failed to parse POMs
java.io.IOException: Cannot run program "/usr/lib/jvm/bin/java" (in directory "/var/lib/jenkins/workspace/build"): error=2, No such file or directory
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
    at hudson.Proc$LocalProc.<init>(Proc.java:252)
    at hudson.Proc$LocalProc.<init>(Proc.java:221)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:996)
    at hudson.Launcher$ProcStarter.start(Launcher.java:508)
    at hudson.maven.AbstractMavenProcessFactory.newProcess(AbstractMavenProcessFactory.java:280)
    at hudson.maven.ProcessCache.get(ProcessCache.java:236)
    at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:802)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:514)
    at hudson.model.Run.execute(Run.java:1907)
    at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Caused by: java.io.IOException: error=2, No such file or directory
    at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
    at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:340)
    at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:271)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
    ... 13 more
Finished: FAILURE

正如所提出的解决方案的不同性质所指出的那样,与本案例类似。我想提醒大家注意,这些错误与权限有关,或者解析 pom 可能隐藏了真正的根本原因,并且错误消息并不总是像应有的那样明确和清晰。


0
投票

我为 jenkins 安装了 Maven 插件,并在根 pom.xml 中提供了 pom.xml 的完全限定路径,它解决了问题


0
投票

我认为发生这种情况的原因是maven有权运行pom.xml,即。 mvn 命令可以通过终端运行,但不能通过 jenkins 运行。 因此,我们需要将当前用户添加到 jenkins 才能正常工作。

关注这篇博文。它对我有用:

博客文章

© www.soinside.com 2019 - 2024. All rights reserved.