java - 无需使用 Maven 重建即可运行 Jenkins 集成测试

标签 java maven jenkins

我在理解 Jenkins 如何与 Maven 交互以创建简单的构建管道时遇到了一些问题。例如,假设我想对以下管道执行操作:

1 Compile code, run unittest, and package to code.
2 Deploy application to test server.
3 Run integration tests.

这将转化为:

1 mvh clean install
2 deploy.sh
3 mvn verify

对于我的单元测试,我使用 surefire,对于集成测试,我使用 failsafe。然而,问题在于 mvn verify 将重新执行整个构建过程。我想做的只是运行集成测试,而不是所有导致验证的步骤。解决这个问题的标准方法是什么?

最佳答案

这样做的 maven 方法是全部使用 maven 来完成。默认的 Maven 构建生命周期对于您要执行的每个步骤都有一个阶段:https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

For example, the default lifecycle comprises of the following phases (for a complete list of the lifecycle phases, refer to the Lifecycle Reference):

validate - validate the project is correct and all necessary information is available

compile - compile the source code of the project

test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed

package - take the compiled code and package it in its distributable format, such as a JAR.

integration-test - process and deploy the package if necessary into an environment where integration tests can be run

verify - run any checks to verify the package is valid and meets quality criteria

install - install the package into the local repository, for use as a dependency in other projects locally

deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

因此,作为集成测试阶段的一部分,您希望将 Artifact 部署到您的测试服务器(您的第 2 步)。然后你所要做的就是运行

mvn clean install

这将清理并执行所有构建、运行单元测试、打包、部署到集成环境、运行集成测试并将 Artifact 安装到本地存储库中的操作。

关于java - 无需使用 Maven 重建即可运行 Jenkins 集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30635990/

相关文章:

jenkins - 错误 Slack 从全局配置发送管道步骤配置值

logging - 在上游作业中显示下游作业的控制台输出

java - 显示 utf-8 波斯语文本 使用 weka 文本分类代码

java - Query TestSet Json 在 Rally Rest API 中返回错误的测试用例列表

java - 通过组合 arraylist-elements 过滤 dir 中的文件名

java - 如何将数组列表从servlet传递到JSP?

java - 将注释处理器集成到同一个项目中

java - Maven故障安全不执行测试

java - 在maven中更改pom上的包装时无法找到或加载主类

maven - 在管道中传递MAVEN_OPTS