欢迎光临
我们一直在努力

Jenkins如何使用publish html report插件展示HTML报告

本篇内容介绍了“Jenkins如何使用publish html report插件展示HTML报告”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

安装插件

  • Manage Jenkins –> Manage Plugins –> 可选插件 –> 搜索 publish html repor

  • 说明:截图中是已安装好插件,所以在已安装中

准备测试代码

  • 新建test_01.py,代码如下

  • 安装python包:pip install pytest-html

# -*- coding: utf-8 -*-
# @Time    : 2021/11/27
# @Author  : 大海
# @File    : test_40.py

import os
def test_add():
    c = 1 + 2
    assert c == 2
if __name__ == '__main__':
    os.system('pytest -s test_02.py --html=report.html --self-contained-html')

Pipeline

pipeline {
    agent any
    stages {
        stage('checkout code') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/分支']], extensions: [], userRemoteConfigs: [[credentialsId: '认证信息', url: '你的仓库地址']]])
            }
        }
        stage('auto test') {
            steps {
                bat 'python test_01.py'
            }
        }
    }
    post {
      always {
         // reportDir 报告所在目录;reportFiles 报告名称;reportName 在Jenkins菜单栏显示的名称 ;reportTitles 点进测试报告显示的Title
         publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: false, reportDir: './', reportFiles: 'report.html', reportName: '测试报告', reportTitles: '测试报告'])
      }
    }
}

查看报告

左侧菜单列表,点击测试报告

解决报告无样式

  • 官网说明:https://www.jenkins.io/doc/book/security/configuring-content-security-policy/

  • 点击 Mange Jenkins 页面,找到Script Console

运行下面的脚本

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")

shift +f5 刷新页面多次(没成功),可以清除浏览器历史,再次进入就会有CSS样式了

“Jenkins如何使用publish html report插件展示HTML报告”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注云搜网网站,小编将为大家输出更多高质量的实用文章!

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。