jenkins pipeline+allure+pytest生成allure报告没有数据的问题解决

问题描述:

  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行。指定后再次执行问题解决!

如下图:

 

 

 
posted @ 2020-06-16 20:57  金刚葫芦娃哈  阅读(4189)  评论(1编辑  收藏  举报