Skip to content

Instantly share code, notes, and snippets.

@bjkmd
Created December 11, 2020 19:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bjkmd/fdf13edde8f14ec825be8fd9e3fc40a3 to your computer and use it in GitHub Desktop.
Save bjkmd/fdf13edde8f14ec825be8fd9e3fc40a3 to your computer and use it in GitHub Desktop.
Jenkins pipeline for comparing jmeter results
node('master') {
        properties(
            [
                    parameters([
                            string(defaultValue: 'run_performance_tests', description: 'Jenkins job to take results from', name: 'Job'),
                            string(defaultValue: '10', description: 'Build number from the job', name: 'FirstBuild'),
                            string(defaultValue: '11', description: 'Build number from the job', name: 'SecondBuild')
                    ])
            ])
    
stage('pulLatestCode'){
    git branch: 'branch', credentialsId: 'GithubBuilds', url: 'https://github.com/user/repository.git'
}
stage('preparation') {
job =     env.Job
buildsFolder = "PATH"
firstBuild = env.FirstBuild
secondBuild = env.SecondBuild
date= System.currentTimeMillis()
jmeterFolder = "PATH"
resultsFolder = "testResults/${date}"
dashboardFolder = "${resultsFolder}/${firstBuild}_${secondBuild}_merged_dashboard"
propertiesFile = pwd()+"/${resultsFolder}/merge.properties"
mergedResultsFile = "${firstBuild}_${secondBuild}_merged.csv"
jvmSettings = "-Xms1024M -Xmx2048M -XX:-UseGCOverheadLimit"
firstFile = sh(returnStdout: true, script: "ls ${buildsFolder}${firstBuild}/archive/testResults/*/*.csv").trim()
secondFile = sh(returnStdout: true, script: "ls ${buildsFolder}${secondBuild}/archive/testResults/*/*.csv").trim()
mergeResultsCMD="java ${jvmSettings} \
    -jar ${jmeterFolder}/lib/cmdrunner-2.0.jar \
    --tool Reporter \
    --generate-csv ${mergedResultsFile} \
    --input-jtl ${propertiesFile} \
    --plugin-type MergeResults"
generateDashboardCMD="${jmeterFolder}/bin/jmeter.sh \
    -o ${dashboardFolder}\
    -g ${resultsFolder}/${mergedResultsFile}"
propertiesTemplate = """
# === FILE 1 ===
inputJtl1=${firstFile}
prefixLabel1=Build_${firstBuild}
includeLabels1=
excludeLabelsl=
includeLabelRegex1=
excludeLabelRegex1=
startOffset1=
endOffset1=
# === FILE 2 ===
inputJtl2=${secondFile}
prefixLabel2=Build_${secondBuild}
includeLabels2=
excludeLabels2=
includeLabelRegex2=
excludeLabelRegex2=
startOffset2=
endOffset2=
"""
}
stage('mergeResults') {
    sh "mkdir  -p ${resultsFolder}"
    sh "echo  '${propertiesTemplate}' > ${propertiesFile}"
    sh mergeResultsCMD
    sh "mv ${mergedResultsFile} ${resultsFolder}/"
}
stage('generateDashboard') {
    sh generateDashboardCMD
}
stage('publishReport') {
    archiveArtifacts allowEmptyArchive: true, artifacts: "${resultsFolder}/**/*", onlyIfSuccessful: true
    publishHTML([
        allowMissing: true,
        alwaysLinkToLastBuild: true,
         keepAll: true,
          reportDir: "${dashboardFolder}",
           reportFiles: "index.html",
            reportName: "HTML Report",
             reportTitles: ""])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment