詹金斯不可读的POM

时间:2018-04-07 23:59:41

标签: java jenkins intellij-idea junit

此错误发布在不同的论坛中,甚至here。我尝试过不同的选择。我尝试更改POM权限。我正在使用默认的maven设置。 JDK是8,Maven 3.5.3。

我只想尝试一个非常简单的junit应用程序。从命令行我运行“mvn test”

没有问题
router.get('/add/:id', function(req, res, next){
    var prodId = req.params.id;
    var cart = new Cart(req.session.cart ? req.session.cart : {})

    Prod.findById(prodId, function(err, prod){
        if (err) {
            return res.redirect('/');
        }
            cart.add(prod, prod.id);
            setTimeout(timer, 20000);  
            req.session.cart = cart;
            res.redirect('/show/' + prodId);
        } else {
            return res.redirect('/');
        }
    });
});

var timer = function(req, res){
    console.log(req.session.cart);
};

但是从Jenkins,从控制台输出我有这个错误:

控制台输出

junitexample amh$ mvn test
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< com.junit:junit-example >-----------------------
[INFO] Building junit-example 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ junit-example ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ junit-example ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ junit-example ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/amhg/Documents/dev/intellik2/junitexample/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ junit-example ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ junit-example ---
[INFO] Surefire report directory: /Users/amhg/Documents/dev/intellik2/junitexample/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running CalculatorTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.045 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.178 s
[INFO] Finished at: 2018-04-08T01:39:52+02:00
[INFO] ------------------------------------------------------------------------

这是我的POM文件

Started by user Andrea
Building in workspace /Users/Shared/Jenkins/Home/workspace/calc
[calc] $ /Users/amhg/apache-maven-3.5.3/bin/mvn -f /Users/amhg/Documents/dev/intellik2/junitexample test
POM file /Users/amhg/Documents/dev/intellik2/junitexample specified with the -f/--file command line argument does not exist
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-readable POM /Users/amhg/Documents/dev/intellik2/junitexample: /Users/amhg/Documents/dev/intellik2/junitexample (Permission denied) @ 
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project  (/Users/amhg/Documents/dev/intellik2/junitexample) has 1 error
[ERROR]     Non-readable POM /Users/amhg/Documents/dev/intellik2/junitexample: /Users/amhg/Documents/dev/intellik2/junitexample (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

我只是做了一个简单的测试:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.junit</groupId>
    <artifactId>junit-example</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>junit-example</name>
    <url>http://maven.apache.org</url>


    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

我不知道还能尝试什么。我打开了与问题相关的所有主题。

还有其他建议吗?

3 个答案:

答案 0 :(得分:1)

我遇到了完全相同的问题-本地Maven构建成功,而詹金斯(Jenkins)失败并出现与您相同的错误。

一旦Jenkins作业开始,它将源代码导入到/your-jenkins/workspace/your-job-name文件夹中,然后开始构建。在DSL中,您必须提及工作空间中pom的路径。

查看Jenkins工作区视图,以查看下载源代码后pom的位置。这将有助于解决问题。

enter image description here

答案 1 :(得分:0)

在您提供的-f选项中。 maven无法识别要阅读的pom

  

-f / Users / amhg / Documents / dev / intellik2 / junitexample test

尝试提供包含.xml

的pom的完整名称
  

-f / Users / amhg / Documents / dev / intellik2 / junitexample nameofpom.xml

答案 2 :(得分:0)

请检查您的 Jenkins 构建 -> 目标和构建 -> POM 中的内容。 你可能换了这两个。