java - Maven 不能在 jenkins 上运行(但它可以通过 eclipse 和命令行运行)

标签 java maven jenkins

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

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

等待 Jenkins 完成收集数据[错误] 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project invalidlogin: Error while storing the mojo 状态:/var/lib/jenkins/workspace/project/invalidlogin/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst(权限被拒绝)-> [帮助 1]

我使用 PhantomJS 作为浏览器。

如何让它在 jenkins 中工作?

  • 我使用 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>

最佳答案

问题确实与权限有关。我在设置时遇到了一些问题,但是我在这里找到了这个指南: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!

关于java - Maven 不能在 jenkins 上运行(但它可以通过 eclipse 和命令行运行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40346441/

相关文章:

java - 打包 Java 应用程序时,属性文件未包含在 jar 文件中

java - 在按钮单击内显示加载 GIF,并在执行操作后再次隐藏它

java - 指定位置管理器在 Android 中广播当前位置的时间间隔

java - 使用 Maven 构建 Geoserver 时出现 MojoExecutionException

java - 未经测试的 Maven 打包/安装(跳过测试)

jenkins - 具有相关参数的参数化 Jenkins 作业

java - new Vector<Object Type> (int ) 之后的 (int ) 代表什么?

java - Mockito - 测试返回类型是否与预期相同

jenkins - 使用 Groovy-Script 在 Jenkins 中分配节点超时

Jenkins 多分支配置 : How to Filter branches based on variable string?