How to Run a JMeter Test with Jenkins 2.0 Pipelines and GitHub
Jenkins 2.0 was released in April 2016. The main addition on the Jenkins 2.0 version is Jenkins Pipelines, which provide higher resilience and flexibility, as well as parameterization abilities and VCS friendliness. For more information on Jenkins 2.0 Pipelines see here.
In this blog post we will go over how to run a JMeter test with Jenkins 2.0 Pipelines and GitHub. This enables you to pull the complete Pipeline script from the Git Repository and lets you manage all changes in your Jenkins project under SCM. No changes are lost, all changes are documented and it’s much easier to manage and maintain your Jenkins project. Also it’s pretty cool.
Here are the steps:
1. Install Jenkins 2.0.
2. Create a Jenkins Pipeline script using Groovy, for running JMeter. Pipelines are defined using Groovy-based DSL so Jenkins and Java APIs can be used to define the job.
In this example, I’m running a JMeter script I created called Jenkins_demo1.jmx.
stage 'Run JMeter Test'
sh '/home/ubuntu/apache-jmeter-3.1/bin/jmeter.sh -n -t /home/ubuntu/Jenkins_demo1.jmx -l test.jtl'
3. Upload the Groovy script to your GitHub Repository.
4. Create a new Jenkins project: New Item -> Pipeline.
5. Check the boxes: ‘GitHub project’ and ‘Build when a change is pushed to GitHub’, and set your GitHub Repository project URL.
6. Configure your pipeline. Choose the ‘Pipeline script from SCM’ option to pull the pipeline script you created from your GitHub Repository.
7. Click ‘Save’.
That’s it! You can change your Jenkins project using the Pipeline script in your GitHub Repository. All changes will be saved, each change will trigger your build and you can manage your project easily and enjoy all of Jenkins' Continuous Integration capabilities. You don’t need to change anything on Jenkins anymore.
For example, I changed my Pipeline script in GitHub to run 250 Virtual Users on my JMeter script (originally it was running 300 Virtual Users):
Now I can see the changes in my Jenkins Project.
The changes triggered the Jenkins job.
Congratulations! You can now easily and efficiently run Pipeline scripts from your GitHub Repository on Jenkins 2.0.