Forked from bjkmd/gist:fdf13edde8f14ec825be8fd9e3fc40a3
Created
December 21, 2020 06:58
-
-
Save polarnik/0efdfe115d75ec9acc91ef9f8bbd6a46 to your computer and use it in GitHub Desktop.
Jenkins pipeline for comparing jmeter results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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