問題描述:
windows下,pipeline指令:
pipeline { agent any environment{ a = 'test' } stages{ stage('example') { steps{ echo 'This is a example' bat ''' cd d:/jenkins/DATA/workspace/pipeline1 pytest test_five.py ''' } } } post { always{ bat 'java -version' bat 'allure --version' script { allure includeProperties: false, jdk: '', report: 'report', results: [[path: 'result']] } } } }
1.生成了allure報告,但是沒有數據,如下:
2.日志:allure-results does not exists,具體如下:
問題分析:
jenkins結合allure的原理是:執行pytest生成xml 文件,然后再使用allure命令生成報告,報告沒有數據有可能會有兩個原因,
1.是沒有生成xml文件
2.生成了xml文件,但沒有被找到;生成的xml和報告沒有在一個目錄下
因此pipelien指令更改如下:
1 pipeline { 2 agent any 3 environment{ 4 a = 'test' 5 } 6 stages{ 7 stage('example') { 8 steps{ 9 echo 'This is a example' 10 bat ''' 11 cd d:/jenkins/DATA/workspace/pipeline1 12 pytest --alluredir=result -s -v test_five.py 13 ''' 14 } 15 16 } 17 } 18 19 post { 20 always{ 21 bat 'java -version' 22 bat 'allure --version' 23 script { 24 allure includeProperties: false, jdk: '', report: 'report', results: [[path: 'result']] 25 } 26 } 27 } 28 29 }
可以發現,我的錯誤是執行pytest測試時,沒有指定測試結果的位置,如上述代碼塊12行。指定后再次執行問題解決!
如下圖: