在管道詹金斯中未执行故障安全集成测试

时间:2019-07-22 01:11:58

标签: maven jenkins maven-failsafe-plugin

我有一个包含三个步骤的管道工具:检出SCM,构建和测试,部署。该项目基于Maven,我使用maven-failsafe-plugin运行集成测试。问题在于,当我通过终端执行mvn clean verify时,一切正常,但是当我执行管道时,集成测试将无法执行。

这里是JenkinsFile:

pipeline {
    agent any
    environment {
            DOCKER_HOST = 'unix:///var/run/docker.sock'
    }

    stages {
        stage('Build and Test') { 
            steps {
                sh "/usr/local/share/apache-maven-3.5.4/bin/mvn clean verify"
            }
        }
        stage('Deploy') {
            steps {
                sh "cp /var/lib/jenkins/workspace/MPT-be-price-quotation/target/price-quotation-1.0-SNAPSHOT.war ~/Documents/deployments/be-price-quotation"
            }
        }
    }
}

在这里pom.xml

 ...  
<profiles>
<!--PROFILO DA ESEGUIRE PER CREARE E INIZIALIZZARE IL DB-->
<profile>
    <id>setup</id>
    <build>
        ...
    </build>
</profile>
</profiles>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
    <plugins>
        ...
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.1</version>
        </plugin>
        ...

    </plugins>
</pluginManagement>

<plugins>


    <!-- PLUGIN PER PREPARARE L'AMBIENTE ED ESEGUIRE I TEST IN CONTAINER DOCKER -->
    <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>0.26.1</version>
        <configuration>
            <autoCreateCustomNetworks>true</autoCreateCustomNetworks>
            <showLogs>true</showLogs>
            <images>
                .
                .
                .
                <image>
                    <alias>maven-setup</alias>
                    <name>maven:3.5-jdk-8</name>
                    <run>
                        <network>
                            <mode>custom</mode>
                            <name>test-network</name>
                            <alias>maven-setup</alias>
                        </network>
                        <namingStrategy>alias</namingStrategy>
                        <log>
                            <prefix>maven-setup</prefix>
                        </log>
                        <volumes>
                            <bind>
                                <volume>${project.basedir}:/usr/src/mymaven</volume>
                                <volume>${settings.localRepository}/../:/var/maven/.m2</volume>
                                <volume>${env.MAVEN_HOME}/conf/settings.xml:/usr/share/maven/conf/settings.xml
                                </volume>
                            </bind>
                        </volumes>
                        <workingDir>/usr/src/mymaven</workingDir>
                        <cmd>mvn initialize -Psetup -Duser.home=/var/maven
                            -Dmaven.repo.local=/var/maven/.m2/repository/
                        </cmd>
                        <dependsOn>
                            <container>mssql-server</container>
                            <container>jboss-wildfly</container>
                        </dependsOn>
                        <wait>
                            <log>BUILD SUCCESS</log>
                            <time>${maven-timeout}</time>
                        </wait>
                    </run>
                </image>

                <image>
                    <alias>maven-it</alias>
                    <name>maven:3.5-jdk-8</name>
                    <run>
                        <network>
                            <mode>custom</mode>
                            <name>test-network</name>
                            <alias>maven-it</alias>
                        </network>
                        <namingStrategy>alias</namingStrategy>
                        <log>
                            <prefix>maven-it</prefix>
                        </log>
                        <user>1000</user>
                        <volumes>
                            <bind>
                                <volume>
                                    ${project.basedir}/src/main/resources/wsdl:${project.basedir}/src/main/resources/wsdl
                                </volume>
                                <volume>${project.basedir}:/usr/src/mymaven</volume>
                                <volume>${settings.localRepository}/../:/var/maven/.m2</volume>
                                <volume>${env.MAVEN_HOME}/conf/settings.xml:/usr/share/maven/conf/settings.xml
                                </volume>
                            </bind>
                        </volumes>
                        <env>
                            <MAVEN_CONFIG>/var/maven/.m2</MAVEN_CONFIG>
                        </env>
                        <workingDir>/usr/src/mymaven</workingDir>
                        <cmd>mvn failsafe:integration-test failsafe:verify
                            -Duser.home=/var/maven
                            -Dmssql-server.jdbc.url=${mssql-server.jdbc.url}
                            -Djboss-wildfly.http.url=http://jboss-wildfly:8080
                        </cmd>
                        <dependsOn>
                            <container>maven-setup</container>
                        </dependsOn>
                        <wait>
                            <log>BUILD SUCCESS</log>
                            <time>${maven-timeout}</time>
                        </wait>
                    </run>
                </image>
            </images>
        </configuration>
        <executions>
            <execution>
                <id>start</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>stop</goal>
                    <goal>start</goal>
                </goals>
            </execution>
            <execution>
                <id>stop</id>
                <phase>verify</phase>
                <goals>
                    <goal>stop</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

</plugins>

</build>
...

mvn clean verify的命令行输出:

[INFO] DOCKER> [maven:3.5-jdk-8] "maven-it": Start container 62b8e470d4b4
maven-it[INFO] Scanning for projects...
maven-it[INFO]
maven-it[INFO] ---------------------< it.mpt.be:price-quotation >----------------------
maven-it[INFO] Building price-quotation 1.0-SNAPSHOT
maven-it[INFO] --------------------------------[ war ]---------------------------------
maven-it[INFO]
maven-it[INFO] --- maven-failsafe-plugin:3.0.0-M3:integration-test (default-cli) @ price-quotation ---
maven-it[INFO]
maven-it[INFO] -------------------------------------------------------
maven-it[INFO]  T E S T S
maven-it[INFO] -------------------------------------------------------
maven-it[INFO] Running it.mpt.be.price.quotation.it.AppTestIT
maven-it2019-07-22 00:18:12 INFO  ReflectionServiceFactoryBean - Creating Service {http://mpt.priv/pricequotation/v1}PriceQuotationService_v1 from WSDL: file:/home/andrea/Documents/MPT/Preventivatore/be-price-quotation/src/main/resources/wsdl/PriceQuotationService_v1.0.wsdl
jboss-wildfly2019-07-22 00:18:13 INFO  TestProcessor - Hello Camel
maven-it[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.882 s - in it.mpt.be.price.quotation.it.AppTestIT
maven-it[INFO]
maven-it[INFO] Results:
maven-it[INFO]
maven-it[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
maven-it[INFO]
maven-it[INFO]
maven-it[INFO] --- maven-failsafe-plugin:3.0.0-M3:verify (default-cli) @ price-quotation ---
maven-it[INFO] ------------------------------------------------------------------------
[INFO] DOCKER> Pattern 'BUILD SUCCESS' matched for container 62b8e470d4b4
maven-it[INFO] BUILD SUCCESS
maven-it[INFO] ------------------------------------------------------------------------
maven-it[INFO] Total time: 6.486 s
maven-it[INFO] Finished at: 2019-07-22T00:18:14Z
maven-it[INFO] ------------------------------------------------------------------------

管道日志:

[INFO] DOCKER> [maven:3.5-jdk-8] "maven-it": Start container f2ab19c6b6eb
maven-it[INFO] Scanning for projects...
maven-it[INFO]
maven-it[INFO] ---------------------< it.mpt.be:price-quotation >----------------------
maven-it[INFO] Building price-quotation 1.0-SNAPSHOT
maven-it[INFO] --------------------------------[ war ]---------------------------------
maven-it[INFO]
maven-it[INFO] --- maven-failsafe-plugin:3.0.0-M3:integration-test (default-cli) @ price-quotation ---
maven-it[INFO]
maven-it[INFO] -------------------------------------------------------
maven-it[INFO]  T E S T S
maven-it[INFO] -------------------------------------------------------
maven-it[INFO]
maven-it[INFO] Results:
maven-it[INFO]
maven-it[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
maven-it[INFO]
maven-it[INFO] ------------------------------------------------------------------------
maven-it[INFO] BUILD FAILURE
maven-it[INFO] ------------------------------------------------------------------------
maven-it[INFO] Total time: 15.130 s
maven-it[INFO] Finished at: 2019-07-22T00:01:14Z
maven-it[INFO] ------------------------------------------------------------------------
maven-it[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M3:integration-test (default-cli) on project price-quotation: /usr/src/mymaven/target/failsafe-reports/failsafe-summary.xml (No such file or directory) -> [Help 1]
maven-it[ERROR]
maven-it[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
maven-it[ERROR] Re-run Maven using the -X switch to enable full debug logging.

0 个答案:

没有答案