Jenkins使用publish html report插件展示HTML报告的方法

作者:爱学习de测试小白 时间:2022-03-31 19:30:54 

前言

  • 前面介绍了Allure报告,本篇来学习普通的HTML如何展示在Jenkins上

安装插件

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

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

Jenkins使用publish html report插件展示HTML报告的方法

准备测试代码

  • 新建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: '测试报告'])
     }
   }
}

查看报告

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

Jenkins使用publish html report插件展示HTML报告的方法

Jenkins使用publish html report插件展示HTML报告的方法

解决报告无样式

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

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

Jenkins使用publish html report插件展示HTML报告的方法

运行下面的脚本

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

Jenkins使用publish html report插件展示HTML报告的方法

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

Jenkins使用publish html report插件展示HTML报告的方法

来源:https://blog.csdn.net/IT_heima/article/details/123513085

标签:Jenkins,publish,html,report,HTML报告
0
投稿

猜你喜欢

  • Python+PyQT5实现手绘图片生成器

    2022-03-11 11:57:21
  • TensorFlow梯度求解tf.gradients实例

    2023-08-16 17:26:03
  • 如何利用PyQt5制作一个简单的登录界面

    2023-11-18 20:36:31
  • Python实现八皇后问题示例代码

    2023-11-23 03:31:40
  • Python2与Python3关于字符串编码处理的差别总结

    2022-05-21 19:09:51
  • ASP 错误代码

    2009-05-11 12:38:00
  • Python lambda 匿名函数优点和局限性深度总结

    2023-07-25 19:22:00
  • matlab中实现矩阵删除一行或一列的方法

    2023-05-18 05:05:31
  • Python中random模块生成随机数详解

    2023-06-13 16:11:52
  • oracle ORA-01114、ORA-27067错误解决方法

    2023-07-15 18:36:39
  • 获取一个数字的个位、十位、百位的函数代码

    2011-02-20 11:06:00
  • Selenium python时间控件输入问题解决方案

    2023-09-05 19:35:25
  • Django如何实现RBAC权限管理

    2021-05-20 19:14:27
  • python中pandas对多列进行分组统计的实现

    2022-06-25 03:50:03
  • 在FLASH中调用ASP的方法

    2009-03-09 18:32:00
  • python爬虫正则表达式之处理换行符

    2021-02-20 05:56:02
  • 利用Python实现数值积分的方法

    2023-07-11 10:16:31
  • SQL Server中单引号的两种处理技巧

    2008-05-23 13:30:00
  • 科讯CMS编辑器会自动更改代码

    2008-12-12 13:00:00
  • 优化Python代码使其加快作用域内的查找

    2021-09-25 06:40:13
  • asp之家 网络编程 m.aspxhome.com