栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

34-Jenkins-使用publish html report插件展示HTML报告

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

34-Jenkins-使用publish html report插件展示HTML报告

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

前言安装插件准备测试代码Pipeline查看报告解决报告无样式


前言

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

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样式了

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/767993.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号