持续集成 Jenkins 持续输出 reportNG 测试报告

Pangluo · 2018年12月22日 · 最后由 Pangluo 回复于 2018年12月23日 · 2032 次阅读

此贴由 markdown 语法编辑,如果有违规请立即删除

前置条件

整体思路,每次构建完的任务, 在 jenkins 配置目录下 workspace 都会生成对应任务新的 reportNG 报告,我们只是把这个文件部署到 http 服务部署出去

在你的 maven 工程下,pom.xml 引入 manven-surefire 插件
这样你当前工程可以使用mvn test mvn clean mvn build 命令 运行 maven 工程 在命令提示符下 在 jenkins 下.

<build>
    <plugins>
        <!-- 实现方式集成maven的surefire插件, Surefire插件用于Maven项目的test阶段以执行单元测试
        集成后我们就可以通过maven命令 maven test 来调动脚本执行了
         -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.7.1</version>
            <configuration>
                <systemPropertyVariables>
                    <org.uncommons.reportng.escape-output>false</org.uncommons.reportng.escape-output>
                </systemPropertyVariables>
                <testFailureIgnore>true</testFailureIgnore>
                <argLine>
                    -Dfile.encoding=UTF-8
                </argLine>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>

jenkins 新建任务 构建一个 maven 工程 ,完成源码托管,完成 Build 配置,Build 里 clean test 两个命令即可完成整个工程的先 clean 后 test,不依赖 eclipse、IDEA 去执行用例

reportNG 报告

每次执行完构建在 target 目录下生成新的 reportNG 报告

执行 clean 会把 用户目录下 .jenkins/workspace/phoenix/target 编译目标文件夹
执行 test 命令会在用户目录下 .jenkins/workspace/phoenix/生成 target 文件夹

apache 新增一个站点,展示 reportNG 报告

apache 添加一个站点用来专属测试报告展示(怎么一个 apche 部署多个站点,这个网上找下解决方案)

这里的路径指向 reportNG 报告文件路径
DocumentRoot "C:\Users\Administrator\.jenkins\workspace\phoenix\target\surefire-reports\html"
<Directory "C:\Users\Administrator\.jenkins\workspace\phoenix\target\surefire-reports\html">
这里的指定访问端口

部署成功后,重启 apache 就可以访问
http://localhost:8899 -> C:\Users\Administrator.jenkins\workspace\phoenix\target\surefire-reports\html\index.html

部署成功后,外网访问

邮件通知

jenkins 项目邮件通知里,重新修改下测试报告路径

测试

再重新构建试一试

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project phoenix: Failed to clean project: Failed to delete C:\Users\Administrator\.jenkins\workspace\phoenix\target\surefire-reports -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

不能清除.jenkins\workspace\phoenix\target\surefire-reports,被 apache 服务占用了
如果你知道解决方法麻烦告诉我。

既然 clean 不了, 任务 Build 里就不 clean,不影响结果

那要下次要 clean 怎么办?我只能说需要 clean 的时候,构建任务 Build 里,添加 clean,构建一遍后,再改回。

构建,测试下邮件。

每次构建后都是最新 report

最佳回复

写脚本把 report 拷贝到 http 服务器

共收到 4 条回复 时间 点赞

写脚本把 report 拷贝到 http 服务器

LEFT 回复

很好的思路,之前 web 根目录就可以换到其他地方。

构建之后执行一个 bat 脚本,把最新的 report 报告拷贝过去就 OK 了

Build 这里就不影响先cleantest


控制台输出

测试报告

web 根目录下的文件

建议你使用 Jenkins 提供的变量,路径不要写死,实现复用

LEFT 回复

好的。/

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册