使用Jenkins的流水线生产Allure报告发送到企业微信

pipeline {
    agent any
 environment {

    name="${JOB_NAME}"
    times="${currentBuild.duration}"
    task="${BUILD_ID}"
    logs="${ChangeLog}"
        }
        
    stages {
        
        stage('拉取代码') {
            steps {
              git credentialsId: '3', url: 'git@gitlab.senseauto.com:tps-qa/test/matrix-autotest.git'
            }
        }
        
        // 这里的install plug-in 是我加的,就是说明,这是stages下的第二个任务 ,就是在pipeline中加单行注释 用 // 就行
        stage('install plug-in') {
            steps {
                echo '开始安装插件'
                sh 'pip3 install -r requirements.txt'
                echo '插件安装完成'
            }
        }
        
        stage('execute auth_system Test') {
             steps {
                echo '开始执行鉴权系统测试'
                sh 'python3 Run/main.py --system_style Authen_style'
                echo '执行测试完成'
            }
        }   
        
        stage('execute device_system Test') {
            steps {
                echo '开始执行接入系统测试'
                sh 'python3 Run/main.py --system_style device_style'
                echo '执行测试完成'
            }
        }
        
        stage('execute data_system Test') {    
            steps {
                echo '开始执行数据系统测试'
                sh 'python3 Run/main.py --system_style data_style'
                echo '执行测试完成'
            }
        }
        
        stage('execute info_system Test') {    
            steps {
                echo '开始执行信息系统测试'
                sh 'python3 Run/main.py --system_style info_style'
                echo '执行测试完成'
            }
        }
        
        stage('execute vehicle_monitor_system Test') {    
            steps {
                echo '开始执行重点车监管系统测试'
                sh 'python3 Run/main.py --system_style monitor_style'
                echo '执行测试完成'
            }
        }
        
        stage('execute general_monitor_system Test') {    
            steps {
                echo '开始执行综合监管测试'
                sh 'python3 Run/main.py --system_style general_monitor'
                echo '执行测试完成'
            }
        }
        
         stage('execute cloud_3d_system Test') {    
            steps {
                echo '开始执行3D系统测试'
                sh 'python3 Run/main.py --system_style cloud_3d_system'
                echo '执行测试完成'
            }
        }
        
        stage('Test port') {
            steps {
                echo '生成报告中.........'
                //sh 'cd ${workspace}'
                allure includeProperties: false, jdk: '',  reportBuildPolicy: 'ALWAYS', report: 'logs/report/report_html', results: [[path: 'logs/report/json_file']]
                echo '报告生成完成'

            }
        }
    }
    
    post { 
        success {
            sh '''
              curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=c927aa95-aef7-4630-8aa6-b94f78ba1525' \
               -H 'Content-Type: application/json' \
               -d '
               {
                    "msgtype": "markdown",
                     "markdown": {      
                        "content": "#### 构建成功 ✅:'$name'项目! \n
                         >### 持续时间:'$times'
                         >### 用户名/密码: user/user
                         >### [<<< 点击查看报告 >>>]('http://10.4.196.81:8080/jenkins/job/Matrix-autotest/$task/allure')"
                     }
                    }'
                '''
                }
                
        failure {
            sh '''
              curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=c927aa95-aef7-4630-8aa6-b94f78ba1525' \
              -H 'Content-Type: application/json' \
              -d '
              {
                    "msgtype": "markdown",
                     "markdown": {      
                        "content": "#### 构建失败 ❌'$name'项目! \n
                         >### 持续时间:'$times'
                         >### 用户名/密码: user/user
                         >### [<<< 点击查看报告 >>>]('http://10.4.196.81:8080/jenkins/job/Matrix-autotest/$task/allure')"
                         
                     }
                    }'
            '''
            echo 'failure'       
                }
                
        unstable {
             sh '''
              curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=c927aa95-aef7-4630-8aa6-b94f78ba1525' \
              -H 'Content-Type: application/json' \
              -d '
              {
                    "msgtype": "markdown",
                     "markdown": {      
                        "content": "#### 构建不稳定,出现部分异常 ❌'$name'项目! \n
                         >### 持续时间: '$times'
                         >### 用户名/密码: user/user
                         >### [<<< 点击查看报告 >>>]('http://10.4.196.81:8080/jenkins/job/Matrix-autotest/$task/allure')"
                      }
                    }'
            '''
            echo 'unstable'       
                }
                
                
             }
        }


第二种:
pipeline {
    agent any
 environment {
    name="${JOB_NAME}"
    times="${currentBuild.duration}"
    task="${BUILD_ID}"
    logs="${ChangeLog}"
        }
        
    stages {
        
        stage('拉取代码') {
            steps {
              git branch: 'main', credentialsId: '4', url: 'git@gitlab.senseauto.com:tps-qa/test/data_platform.git'
            }
        }
        
        // 这里的install plug-in 是我加的,就是说明,这是stages下的第二个任务 ,就是在pipeline中加单行注释 用 // 就行
        stage('install plug-in') {
            steps {
                echo '开始安装插件'
                sh 'pip3 install -r requirements.txt'
                echo '插件安装完成'
            }
        }
        
        stage('execute system Test') {
            steps {
                echo '执行绝影[数据平台]测试'
                sh 'python3 config_file.py "${IP}" "${split_pages}" "${token}" "${Content_Type}"'
                sh 'python3 Run/main.py "${Choice_Space}"'
                echo '执行测试完成'
            }
        } 
        
        stage('Test port') {
            steps {
                echo '生成报告中.........'
                //sh 'cd ${workspace}'
                allure includeProperties: false, jdk: '',  reportBuildPolicy: 'ALWAYS', report: 'logs/report/report_html', results: [[path: 'logs/report/json_file']]
                echo '报告生成完成'

            }
        }
    }
    
    post { 
        success {
            sh '''
              curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=9e23e755-3267-4a1c-a34d-2dcb4eb4a6e5' \
              -H 'Content-Type: application/json' \
              -d '
              {
                    "msgtype": "markdown",
                     "markdown": {      
                        "content": "#### 构建成功 ✅:'$name'项目! \n
                         >### 持续时间:'$times'
                         >### 用户名/密码: user/user
                         >### [<<< 点击查看报告 >>>]('http://10.4.196.81:8080/jenkins/job/Data_Platform_Test/$task/allure')"
                     }
                    }'
                '''
                }
                
        failure {
            sh '''
              curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=9e23e755-3267-4a1c-a34d-2dcb4eb4a6e5' \
              -H 'Content-Type: application/json' \
              -d '
              {
                    "msgtype": "markdown",
                     "markdown": {      
                        "content": "#### 构建失败 ❌'$name'项目! \n
                         >### 持续时间:'$times'
                         >### 用户名/密码: user/user
                         >### [<<< 点击查看报告 >>>]('http://10.4.196.81:8080/jenkins/job/Data_Platform_Test/$task/allure')"
                         
                     }
                    }'
            '''
            echo 'failure'       
                }
                
        unstable {
             sh '''
              curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=9e23e755-3267-4a1c-a34d-2dcb4eb4a6e5' \
              -H 'Content-Type: application/json' \
              -d '
              {
                    "msgtype": "markdown",
                     "markdown": {      
                        "content": "#### 构建不稳定,出现部分异常 ❌'$name'项目! \n
                         >### 持续时间: '$times'
                         >### 用户名/密码: user/user
                         >### [<<< 点击查看报告 >>>]('http://10.4.196.81:8080/jenkins/job/Data_Platform_Test/$task/allure')"
                      }
                    }'
            '''
            echo 'unstable'       
                }
                
                
             }
        }
        

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值