【问题标题】:Maven doesnt work on jenkins (but it does through eclipse and command line)Maven 在 jenkins 上不起作用(但它通过 eclipse 和命令行起作用)
【发布时间】:2026-01-04 07:00:01
【问题描述】:

我有几个 CI 测试,都在 maven 中。当我在本地(Windows 10)的 Eclipse 中运行它们以及通过 ec2 linux 服务器中的命令行运行它们时,构建成功。

只有当我从 Jenkins 构建相同的项目时,我才会收到以下错误:

Waiting for Jenkins to finish collecting data[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project invalidlogin: Error while storing the mojo status: /var/lib/jenkins/workspace/project/invalidlogin/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst (Permission denied) -> [Help 1]

我使用 PhantomJS 作为浏览器。

如何让它在詹金斯工作?

  • 我使用 chmod 更新了权限,但仍然得到相同的结果。
  • 为什么这会通过控制台而不是通过 jenkins 运行?

这是我的pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>InvalidLoginV1</groupId>
  <artifactId>invalidlogin</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>invalidcredentials</name>
  <description>invalidcredentials</description>

  <properties>
<suiteXmlFile>src/main/resources/testng.xml</suiteXmlFile>

</properties> 

<dependencies>
<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.8</version>
  <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-server</artifactId>
    <version>2.34.0</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>com.github.detro.ghostdriver</groupId>
    <artifactId>phantomjsdriver</artifactId>
    <version>1.0.4</version>
    <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.19.1</version>
  <type>maven-plugin</type>
</dependency>


</dependencies>  

<build>


<plugins>

    <plugin>
          <groupId>com.github.klieber</groupId>
          <artifactId>phantomjs-maven-plugin</artifactId>
          <version>0.7</version>
    </plugin>



<plugin>



<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>


</plugins>

</build>

</project>

【问题讨论】:

  • 看起来是权限问题。您是否尝试将这些文件的读/写权限授予 jenkins 用户?
  • @Reimeus 不,我认为由于我能够通过命令行运行它们,因此可以在 jenkins 中运行。请问如何授予此权限?
  • 其实你应该先检查一下jenkins用户是否拥有/var/lib/jenkins及以下的所有文件,然后做一个chmod来设置权限
  • @Reimeus 非常感谢,我会这样做的。所以为了检查这是正确的命令吗? sudo chown -R me:me /Users/Shared/Jenkins 并更改我应该使用 sudo chmod -R 755 /path/to/project/directory 的权限是您的意思吗?
  • 看起来是对的 :)

标签: java maven jenkins


【解决方案1】:

问题确实与权限有关。我在设置时遇到了一些问题,但是我在这里找到了本指南:http://blog.manula.org/2013/03/running-jenkins-under-different-user-in.html

基本上你需要在服务器上添加一个预先存在的用户作为 jenkins 用户。 sudo vim /etc/sysconfig/jenkins

完成后,只需更改 jenkins home、webroot 和日志的所有权

chown -R user:user/var/lib/jenkins 
chown -R user:user/var/cache/jenkins
chown -R user:user/var/log/jenkins

感谢@Reimeus!

【讨论】:

  • 还请提及它在 debian 系统中的位置,我想很多人认为答案中的内容就足够了。非常感谢..!
【解决方案2】:

在您的项目上运行 chmod 命令可能会解决您的问题

chmod -R 777 projectfoldername

【讨论】:

  • 将所有权限授予所有人并不是最佳做法。真的需要这些权限吗?