Sample Code for Jenkins Pipeline Java Performance Testing
The sample code is as follows:
pipeline {
agent any
options {
timeout(time: 1, unit: 'HOURS')
}
parameters {
string(name: 'GIT_URL', defaultValue: 'https://gitee.com/devkit-pipeline/java_demo.git', description: '--> git url <--')
string(name: 'GIT_BRANCH', defaultValue: 'master', description: '--> code branch <--')
string(name: 'GIT_TARGET_DIR_NAME', defaultValue: 'java_demo', description: '--> code branch <--')
}
stages{
stage('Git Code') {
agent {
label 'kunpeng_java_builder'
}
steps {
echo '====== Obtaining the source code ======'
checkout scmGit(branches: [[name: "${params.GIT_BRANCH}"]],
browser: github("${params.GIT_URL}"),
extensions: [[$class: 'RelativeTargetDirectory',
relativeTargetDir: "${params.GIT_TARGET_DIR_NAME}"],
cleanBeforeCheckout(deleteUntrackedNestedRepositories: true)],
userRemoteConfigs: [[url: "${params.GIT_URL}"]])
}
}
stage('java-performance-analysis') {
agent {
label 'kunpeng_java_builder'
}
steps {
echo '====== java-performance-analysis ======'
sh '''
if [ ! -d "./report_dir" ]; then mkdir -p ./report_dir; fi
/usr/bin/rm -rf ./report_dir/*.html
# Stop further steps and return immediately if the return value is not 0.
set -e
CURDIR=$(pwd)
# Delete the report generated by JMeter last time (file and path specified by the -l and -o parameters in the JMeter command).
rm -rf /home/tester/report /home/tester/result.html
# Run Java performance data collection.
/root/.local/devkit_tester/bin/entrance -i 160.0.1.2,160.0.1.3 -u root -f /root/.ssh/id_rsa -D 160.0.1.5 -a spring-boot -d 10 -g /root/spring-boot -j "sh /root/apache-jmeter-5.6.3/bin/jmeter.sh -nt /root/Test_request.jmx -l /home/tester/result.html -eo /home/tester/report" -o ./report_dir -m /root/.local/bisheng-jdk-17.0.10
'''
}
post {
always {
publishHTML(target: [allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll : true,
reportDir : './report_dir',
reportFiles : 'devkit_performance_report.html',
reportName : 'Java Performance Report']
)
}
}
}
}
}
- /home/tester/report: JMeter report output path.
- /home/tester/result.html: Result file generated by JMeter.
- /root/.local/devkit_tester/bin/entrance: Path to the Java Performance Testing tool.
- /root/.ssh/id_rsa: Path to the private key.
- spring-boot: Name of the application from which data is to be collected.
- /root/spring-boot: Path to the code downloaded using git clone on the worker node.
- /root/apache-jmeter-5.6.3/bin/jmeter.sh: Path to the JMeter tool.
- /root/Test_request.jmx: Path to JMeter test files.
- /root/.local/bisheng-jdk-17.0.10: Path to BiSheng JDK 17.
Replace the preceding example values with actual values.
Parent topic: Java Performance Testing Tool