CI-基于JMeter的性能测试

2021-02-08  本文已影响0人  _夏兮

一、JMeter监控-influxDB+Grafana
这里的监控主要是使用influxDB+Grafana。参考https://blog.csdn.net/you297043284/article/details/105015352/?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-2&spm=1001.2101.3001.4242

image.png
二、JMeter Docker 化
构建Docker镜像 : https://www.jianshu.com/p/69f1aa64a92b
三、构建Pipeline
  1. 代码管理
    将可执行脚本*.jmx文件push到GitLab repo。
    2.编写pipeline
    这里包含了 checkout,build image,perfrom test,generate test report。
pipeline {

    parameters {
        string(defaultValue: 'master', description: '', name: 'BRANCH')
    }


    agent { node { label 'test' } }

    stages {
        stage('Prepare') {
            steps {
                checkout([$class: 'GitSCM',
                          branches: [[name: "${BRANCH}"]],
                          doGenerateSubmoduleConfigurations: false,
                          extensions: [[$class: 'RelativeTargetDirectory',
                                        relativeTargetDir: ''],
                                       [$class: 'CloneOption',
                                        honorRefspec: true,
                                        noTags: false,
                                        reference: '',
                                        shallow: false,
                                        timeout: 30]],
                          submoduleCfg: [],
                          userRemoteConfigs: [[credentialsId: '1*****c',
                                               refspec: "+refs/heads/${BRANCH}:refs/remotes/origin/${BRANCH}",
                                               url: 'git@git.ringcentral.com:***/***.git']]])
            }
        }

        stage('Build') {
            steps {
                script {
                    sh '''
                    cp ./CI-files/DockerBases/Dockerfile.jmeter-plugin .
                    cp ./CI-files/JMeter/build.sh .
                    cp ./CI-files/JMeter/run.sh .
                    cp ./CI-files/JMeter/entrypoint.sh .
                    ls
                    chmod +x $WORKSPACE/run.sh
                    chmod +x $WORKSPACE/entrypoint.sh
                    chmod +x $WORKSPACE/build.sh
                    $WORKSPACE/build.sh
                    '''
                }
            }
        }

        stage('Test') {
            steps {
                script {
                    sh '''
                    export SCRIPT="test/LTI_Test_Plan.jmx"
                    export JTL="test/LTI_Test_Plan.jtl"
                    export LOG="test/LTI_Test_Plan.log"
                    export Report="./Report"
                    rm -rf ${JTL} ${LOG} ${Report}
                    $WORKSPACE/run.sh -n -t ${SCRIPT} -l ${JTL} -j ${LOG} -e -o ${Report}
                    docker rm jmeter
                    '''
                }
            }
        }
        stage('Report') {
                steps {
                    dir("$WORKSPACE") {
                        publishHTML (target : [allowMissing: true,
                            alwaysLinkToLastBuild: true,
                            keepAll: true,
                            reportDir: 'Report',
                            reportFiles: 'index.html',
                            reportName: 'LIT Performance Test Report'])
                    }
                }
            }
    }
}

3.配置jenkins job

配置默认分支 image.png
配置pipeline
image.png
上一篇下一篇

猜你喜欢

热点阅读