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

mbskvtky  于 2023-11-17  发布在  Jenkins
关注(0)|答案(4)|浏览(273)

我在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

字符串

des4xlb0

des4xlb01#

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

chmod +r /home/tes/pom.xml

字符串

xyhw6mcr

xyhw6mcr2#

在我的例子中,原因是我没有JDK,而只是在全局工具配置> JDK > JDK安装的JAVA_HOME中配置了JRE。事实上,Jenkins警告你路径没有指向包含JDK的东西。
Jenkins文档中的Java需求部分指出,某些插件(如Maven Integration或Docker Pipeline)需要JDK。因此必须检查这一点,因为它会导致奇怪的错误:

> 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的解析可能隐藏了真实的根本原因,并且错误消息并不总是像它们应该的那样明确和清晰。

yvt65v4c

yvt65v4c3#

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

flmtquvp

flmtquvp4#

我认为发生这种情况的原因是maven有权运行pom.xml,即mvn命令可以通过终端运行,但不能通过jenkins。所以我们需要将当前用户添加到jenkins以使其工作。
关注这篇博客。它对我很有效:
blogpost

相关问题