Jenkins – Perfomance testing (JMeter + Ant + Slack)

On the server with Jenkins download JMeter

Also need JMeterPluginsCMD

Create a directory for storage:

mkdir -p /var/lib/jmeter

Download and unzip the contents of two archives to this directory.

So that the structure is as follows:

root@jenkins:~# ll /var/lib/jmeter/
total 64K
drwxr-xr-x  8 jenkins jenkins 4.0K Apr 24 15:39 .
drwxr-xr-x 37 root    root    4.0K Mar 22 10:29 ..
drwxr-xr-x  5 jenkins jenkins 4.0K Apr 24 17:47 bin
drwxr-xr-x  5 jenkins jenkins 4.0K Mar 10 08:41 docs
drwxr-xr-x  2 jenkins jenkins 4.0K Mar 10 08:43 extras
drwxr-xr-x  4 jenkins jenkins 4.0K Apr 24 17:47 lib
-rw-r--r--  1 jenkins jenkins  15K Mar 10 10:08 LICENSE
drwxr-xr-x  4 jenkins jenkins 4.0K Mar 10 10:08 licenses
-rw-r--r--  1 jenkins jenkins  172 Mar 10 10:08 NOTICE
drwxr-xr-x  6 jenkins jenkins 4.0K Mar 10 09:58 printable_docs
-rw-r--r--  1 jenkins jenkins  10K Mar 10 10:08 README.md

We create a repository with the following contents.

We create an Item for Multibranch Pipeline in Jenkins.

Content of Jenkinsfile:

pipeline {
    agent any
    parameters {
        string(name: 'SERVER_URL', defaultValue: 'example.org', description: 'URL for load test')
        string(name: 'SITE_PATH', defaultValue: '/', description: 'Path for URL. Default - "/"')
        string(name: 'NUMBER_OF_THREADS', defaultValue: '10', description: 'Number of Threads (Users). Default - 10')
        string(name: 'RAMP_TIME', defaultValue: '5', description: 'Ramp-Up Period. Default - 5(sec)')
        string(name: 'DURATION_TIME', defaultValue: '5', description: 'Duration (seconds). Default - 5')
        string(name: 'STARTUP_DELAY', defaultValue: '5', description: 'Startup delay (seconds). Default - 5')
        booleanParam(name: 'DELETE_CACHE', defaultValue: false, description: 'Toggle this value to build with cache clearing.')
    }
    options {
        ansiColor('xterm')
        timeout(time: 30, unit:'MINUTES')
        timestamps()
    }
    environment {
        def ANT = '/usr/bin/ant'
        def JMETER = '/var/lib/jmeter/bin/jmeter'
        def JMETER_HOME = '/var/lib/jmeter/'
        def TEMPLATE = 'SITE_SIMPLE.jmx'
        // Perository
        def GIT_REPO = 'https://git.artem.services/scm/dev/jenkins-jmeter.git'
        def GIT_CRED = 'svc-bitbucket'
        // Slack
        def SLACK_CHANNEL_ID = credentials('artem-slack-channel-id-debug')
        def SLACK_TOKEN = credentials('artem-slack-token')
        def GIF_SUCCESS = giphySearchRandomByKeyword(credentialsId: 'giphy-api-key', keyword: "hacker", rating: 'g', imageSize: 'downsized_medium')
    }
    stages {
        stage ('Delete work dir') {
            when { expression { return params.DELETE_CACHE } }
            steps {
                deleteDir()
                git branch: "${BRANCH_NAME}", credentialsId: "${GIT_CRED}", url: "${GIT_REPO}"
            }
        }      
        stage ('Configure template') {
            when { branch 'master' }
            steps {
                sh 'envsubst < "ant/templates/\"${TEMPLATE}\"" > "ant/templates/\"${TEMPLATE}\".tmp"'
                sh 'envsubst < "ant/build/build.properties" > "ant/build.properties"'
            }
        }
        stage ('Load test') {
            when { branch 'master' }
            steps {
                sh "cd ant && ${ANT} clean"
                sh "cd ant && ${ANT} run"
                sh "cd ant && ${ANT} generate-report"
                sh "cd ant && ${ANT} generate-chart"
                sh "wget ${GIF_SUCCESS} -O ant/result/success.gif"
            }
        }
    } 
    post {
        always {
            sh "rm ant/templates/${TEMPLATE}.tmp | true"
            sh "rm ant/build.properties | true"
        }
        success {
            slackSend channel: "${SLACK_CHANNEL_ID}", color: 'good', message: "Perfomance test domain: `\"${SERVER_URL}\"` was successful."
            script {
                sh "chmod +x ./upload_images.sh"
                sh "./upload_images.sh ${SLACK_CHANNEL_ID} ${SLACK_TOKEN}"
            }
        }
        failure {
            slackSend channel: "${SLACK_CHANNEL_ID}", color: 'danger', message: "Perfomance test domain: `\"${SERVER_URL}\"` was finished with some error. Watch the Jenkins Console Output: ${JOB_URL}${BUILD_ID}/consoleFull"
        }
    }
}

 

Item performs load testing, generates a report and png graphics, and sends the graphics to the Slack channel. In this Item, Giphy Plugin is used, either connect it, or delete its lines from “Jenkinsfile” and “upload_images.sh

For the “ant generate-chart” command, additional plugins may be required, to do this, go to the directory with the repository contents and execute the command:

ant install-plugins

 

Test result:

Tagged: Tags

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments