linux+jenkins生成測試報告及任意IP打開鏈接能看到allure報告


前言:

曾經你有沒有為allure測試報告而困惑?那么相必可以幫助到你。不知道如何在linux服務器上部署一個靜態thml,把allure報告靜態文件部署,有的使用tomcat部署,有的人打開jenkins查看。

而我,部署一個node.js的Anywhere,它是一個隨啟隨用的靜態服務器,它可以隨時隨地將你的當前目錄變成一個靜態文件服務器的根目錄。由此我認為是非常方便。

本次學習的內容:

  • linux環境下:jenkins + allure 插件生成測試報告
  • linux環境下:node.js +Anywhere + html 生成任意IP都能查看到的allure報告

一、jenkins + allure

首先得安裝好 jenkins、python、pytest,小龍使用的是docker jenkins,詳細請看這篇:https://www.cnblogs.com/gsxl/p/12129333.html

1、jenkins 安裝插件:Allure Commandline

輸入:allure 查找出插件,並安裝重啟(喝杯茶...)

2、全局工具配置中 → Allure Commandline 新增隨便起個名字,應用保存,如下圖:

3、構建設置:Execute shell 、構建后操作設置

# /bin/bash
cd ${WORKSPACE}/xxx/testCase
pytest --alluredir ${WORKSPACE}/report

 最后 應用保存。

4、如果需要指定html文件目錄需在高級設置中配置(用來起一個小服務,任何人都可以訪問鏈接的allure報告),如下圖:

 最后構建,可以查看到allure報告:

 點擊打開的allure報告:

 二、 node.js +Anywhere + html

基於jenkins中構建我們獲得了一個html文件,那么我們可以使用node.js +Anywhere起一個服務,這樣任何IP訪問便可以看到啦。

而且只需要后台啟動一次即可,有新的數據它也會獲取數據展示出來,這樣就不需要經常重啟Anywhere服務了。

1、安裝 node.js:

curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -0
sudo yum -y install nodejs

2、查看node版本:

[root@iZbp19lugf22zbsubsf1y6Z ~]# node -v 
v8.17.0

3、安裝 Anywhere

繼續喝杯茶等一會就好了

npm install anywhere -g

4、查看幫助:

[root@iZbp19lugf22zbsubsf1y6Z ~]# anywhere --help
Usage:
  anywhere --help // print help information
  anywhere // 8000 as default port, current folder as root
  anywhere 8888 // 8888 as port
  anywhere -p 8989 // 8989 as port
  anywhere -s // don't open browser
  anywhere -h localhost // localhost as hostname
  anywhere -d /home // /home as root
  anywhere -l // print log
  anywhere -f // Enable history fallback

5、到html文件夾下啟動服務:

先到文件夾下確認:

[root@iZbp19lugf22zbsubsf1y6Z html]# ll
total 2200
-rw-r--r--  1 1000 1000  682840 Jun 26 00:14 app.js
drwxr-xr-x  4 1000 1000    4096 Jun 26 00:15 data
drwxr-xr-x  2 1000 1000    4096 Jun 26 00:14 export
-rw-r--r--  1 1000 1000      57 Jun 26 00:14 favicon.ico
drwxr-xr-x  2 1000 1000    4096 Jun 26 00:14 history
-rw-r--r--  1 1000 1000     657 Jun 26 00:14 index.html
drwxr-xr-x 11 1000 1000    4096 Jun 26 00:14 plugins
-rw-r--r--  1 1000 1000 1539624 Jun 26 00:14 styles.css
drwxr-xr-x  2 1000 1000    4096 Jun 26 00:15 widgets
[root@iZbp19lugf22zbsubsf1y6Z html]# pwd
/root/jenkins/workspace/xxx/report/html

啟動服務,指定8085端口:anywhere -p 8085

[root@iZbp19lugf22zbsubsf1y6Z html]# anywhere -p 8085
Running at http://172.16.128.251:8085/
Also running at https://172.16.128.251:8086/

6、打開瀏覽器輸入ip+port 訪問:

 7、最后確定正常后,先 kill 掉,再用后台的方式來運行:

①殺掉相關的進程:ps -aux | grep anywhere|xargs kill -9

②后台啟動服務:nohup anywhere -p 8085 >any.out 2>&1 &

 結果便是后台運行着,查看進程:

[root@iZbp19lugf22zbsubsf1y6Z html]# ps -ef | grep anywhere
root     28278 27577  0 10:30 pts/0    00:00:00 node /usr/bin/anywhere -p 8085
root     28456 27577  0 10:31 pts/0    00:00:00 grep --color=auto anywhere
[root@iZbp19lugf22zbsubsf1y6Z html]# 

我們可以打開瀏覽器看一下有沒有毛病。本次分享結束,謝謝謝大家!

如有疑問或更多交交流加QQ群:482713805


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM