【问题标题】:Jenkins jobs for spring boot application with Integration testing带有集成测试的 Spring Boot 应用程序的 Jenkins 作业
【发布时间】:2020-05-26 04:49:21
【问题描述】:

以下是我的场景。

我有我的应用程序,它建立在带有嵌入式 tomcat 服务器的 Spring boot 上。在我的应用程序中,我有单元测试和集成测试。

首先,我想将我的应用程序构建为一个 maven 包 (jar),它将涵盖所有单元测试,然后下一步是将 jar 文件作为 Spring Boot 应用程序 ((java -jar myapplication.jar) 运行启动 tomcat 服务器。作为最后一步,我想在正在运行的 spring boot 应用程序之上运行我的集成测试。

要在 Jenkins 中实现这一点,最好的解决方案是什么。

  1. 是否有可能只有一个 Jenkins 工作并实现上述场景? (例如在构建后的步骤中,使用命令将生成的 jar 作为应用程序运行并在其上运行集成测试)

  2. Else 将在 Jenkins 中创建 3 个作业(一个用于 maven 包,第二个用于部署生成的 jar 文件并运行应用程序,第三个用于在正在运行的应用程序之上运行集成测试。

请提出最佳解决方案。

提前致谢。

巴拉。

【问题讨论】:

    标签: java spring-boot maven jenkins


    【解决方案1】:

    这应该会有所帮助(如果您使用 maven 构建项目)。 一般的想法是使用您的构建工具,而不是在一个 Jenkins 作业中管理整个过程本身。

    <plugin>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-maven-plugin</artifactId>
       <executions>
          <execution>
             <id>pre-integration-test</id>
             <goals>
                <goal>start</goal>
             </goals>
          </execution>
          <execution>
             <id>post-integration-test</id>
             <goals>
                <goal>stop</goal>
             </goals>
          </execution>
       </executions>
    </plugin>
    

    【讨论】:

    • 有关“实时”示例,请在此处参考我的一个旧项目github.com/tkachenkoas/eyfo-falafel。还有一个自述文件 -> 查看“eyfo-backend”模块的构建配置。 IT 完全按照您想要的方式运行
    • 谢谢。我试过这种方式及其工作。当它如此简单时,我想知道为什么许多人在后期构建步骤中设置多个工作或做复杂的事情。至少这就是我通过参考互联网上的文章推断出来的。您建议的选项是否可从某些特定的 Maven 版本中获得?
    • 与spring-boot-maven-plugin有关,与maven没有直接关系。实际上,即使没有 Spring Boot,也可以使用嵌入式 tomcat 插件。
    猜你喜欢
    • 2018-06-28
    • 2014-08-12
    • 2017-04-20
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    • 2018-09-18
    • 2020-04-25
    • 1970-01-01
    相关资源
    最近更新 更多