Mule - 当代码覆盖率小于预定义阈值时,如何使 jenkins 管道失败?

发布于 2025-01-13 09:45:09 字数 210 浏览 0 评论 0原文

我用 Munits 构建了一个 Mule API。我想使用詹金斯管道构建和部署应用程序。然而,在构建之前,部署,我想执行 Maven clean 测试并检查代码覆盖率是否小于某个 x%。如果是,那么我想让 Mule 云中心的构建/部署失败。

当代码覆盖率低于预定义的阈值(比方说 80%)时,是否有 Jenkins 插件或任何选项可以使 jenkins 管道失败?

谢谢, 巴拉

I have a built a Mule API with Munits. I would like to build and deploy the application using jenkins pipeline. However, before build & deploy, I would like to execute maven clean test and check if code coverage is less than some x%. if yes, then I would like to fail the build/deployment to Mule cloud hub.

Is there a Jenkins plugin or any option to fail the jenkins pipeline when the code coverage is less than pre-defined threshold (let's say 80%)?

Thanks,
Bala

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪若未夕 2025-01-20 09:45:09

看起来该主题已在 Maven 中的 MUnit 文档中进行了介绍:



<plugin>
    <groupId>com.mulesoft.munit.tools</groupId>
    <artifactId>munit-maven-plugin</artifactId>
    <version>${munit.version}</version>

    <executions>
        <execution>
            <id>test</id>
            <phase>test</phase>
            <goals>
                <goal>test</goal>
                <goal>coverage-report</goal>
            </goals>
        </execution>
    </executions>

    <configuration>
        <coverage>
            <runCoverage>true</runCoverage>
            <failBuild>false</failBuild>

            <requiredApplicationCoverage>75</requiredApplicationCoverage>
            <requiredResourceCoverage>50</requiredResourceCoverage>
            <requiredFlowCoverage>50</requiredFlowCoverage>

            <formats>
                <format>console</format>
                <format>html</format>
            </formats>
        </coverage>
    </configuration>
</plugin>

如果将适当的阈值(例如 requiredApplicationCoverage)设置为所需的值,并且覆盖率不够高,则 Maven 测试阶段将失败。由于 Jenkins 只执行 Maven,它也会失败。

Looks like the topic is covered in MUnit documentation for coverage in Maven:



<plugin>
    <groupId>com.mulesoft.munit.tools</groupId>
    <artifactId>munit-maven-plugin</artifactId>
    <version>${munit.version}</version>

    <executions>
        <execution>
            <id>test</id>
            <phase>test</phase>
            <goals>
                <goal>test</goal>
                <goal>coverage-report</goal>
            </goals>
        </execution>
    </executions>

    <configuration>
        <coverage>
            <runCoverage>true</runCoverage>
            <failBuild>false</failBuild>

            <requiredApplicationCoverage>75</requiredApplicationCoverage>
            <requiredResourceCoverage>50</requiredResourceCoverage>
            <requiredFlowCoverage>50</requiredFlowCoverage>

            <formats>
                <format>console</format>
                <format>html</format>
            </formats>
        </coverage>
    </configuration>
</plugin>

If you set the appropriate threshold (for example requiredApplicationCoverage) to the desired value it will fail the Maven test phase if coverage is not high enough. Since Jenkins just executes Maven it will fail too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文