前言
安装插件
- 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报告的文章就介绍到这了,更多相关jenkins展示html报告内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!