我在理解 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/