Java,Maven + Jenkinsfile-找不到类路径

时间:2019-06-03 09:54:15

标签: java maven jenkins jenkins-pipeline pom.xml

我有一个奇怪的人。我正在使用命令行在本地通过Maven成功运行一系列Java测试:

LeveneS@WS3748 MINGW64 /h/Coding/workspace/[MY-PROJECT] (initalCommit)
$ mvn surefire-report:report test site
[INFO] Scanning for projects...
[INFO]
[INFO] ---< [MY-PROJECT] >----
[INFO] Building [MY-PROJECT] 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ...etc...
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.ExampleTest

40 Scenarios (40 passed)
91 Steps (91 passed)
0m0.322s

[INFO] Tests run: 131, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.01 s - in com.example.ExampleTest

我想使用多分支管道在Jenkins中运行它;所以我这样创建了一个Jenkinsfile:

pipeline {
  agent { docker { image 'maven:3.6.1' } }
  stages {
    stage('Installation') {
      steps {
        sh 'mvn --version'
        sh 'mvn install'
      }
    }
    stage('Run') {
      steps {
        sh 'mvn surefire-report:report test site'
      }
    }
  }
}

但是,当我在Jenkins中运行它时,出现以下错误:

+ mvn surefire-report:report test site
[INFO] Scanning for projects...
[INFO] 
[INFO] ---< [MY-PROJECT] >----
[INFO] Building [MY-PROJECT] 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ...etc...
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.ExampleTest
No features found at [classpath:com/example]

0 Scenarios
0 Steps
0m0.000s

[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.442 s - in com.example.ExampleTest

似乎找不到我的类路径...但是它在本地运行,所以我看不到为什么它在詹金斯上会失败;在任何情况下;这是我的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>[MY-PROJECT]</groupId>
  <artifactId>[MY-PROJECT]</artifactId>
  <version>0.0.1-SNAPSHOT</version>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
  <build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-site-plugin</artifactId>
      <version>3.7.1</version>
    </plugin>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.1</version>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>3.0.0-M3</version>
    </plugin>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
            <execution>
                <goals>
                    <goal>exec</goal>
                </goals>
                <configuration>
                    <classpathScope>test</classpathScope>
                    <executable>java</executable>
                    <arguments>
                        <argument>-classpath</argument>
                        <classpath />
                        <argument>cucumber.api.cli.Main</argument>
                        <argument>--plugin</argument>
                        <argument>json:${project.build.directory}/cuke-results.json</argument>
                        <argument>--glue</argument>
                        <argument>com.example</argument>
                        <argument>--strict</argument>
                        <argument>${basedir}/src/test/java/com/example</argument>
                    </arguments>
                </configuration>
            </execution>
        </executions>
    </plugin>
  </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <version>3.3.0</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
    </dependency>
    <dependency>
      <groupId>info.cukes</groupId>
      <artifactId>cucumber-java</artifactId>
      <version>1.2.3</version>
    </dependency>
    <dependency>
      <groupId>info.cukes</groupId>
      <artifactId>cucumber-junit</artifactId>
      <version>1.2.3</version>
    </dependency>
    <dependency>
      <groupId>org.json</groupId>
      <artifactId>json</artifactId>
      <version>20180813</version>
    </dependency>
  </dependencies>
</project>

0 个答案:

没有答案
相关问题