DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Implementing CI/CD Pipelines With Jenkins and Docker
  • Pipeline as a Service: How To Test Pipelines in GitLab
  • Getting Started With Jenkins
  • Test Automation: Maven Profiles and Parallelization in Azure Pipelines Using IaaS

Trending

  • AI’s Role in Everyday Development
  • Fixing Common Oracle Database Problems
  • Teradata Performance and Skew Prevention Tips
  • Scaling Mobile App Performance: How We Cut Screen Load Time From 8s to 2s
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. Running a JMeter Test Via Jenkins Pipeline

Running a JMeter Test Via Jenkins Pipeline

We take a look at how to run a JMeter test using Jenkins' "Pipeline" project type. Read on for more details.

By 
Dmitri Tikhanski user avatar
Dmitri Tikhanski
·
Sep. 13, 16 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
18.9K Views

Join the DZone community and get the full member experience.

Join For Free

The release of Jenkins 2.0 has introduced a new project type — Pipeline, which was previously available through plugins only. Starting from Jenkins 2.0, Pipeline projects come out of the box.

Pipeline builds have several major advantages over the usual “freestyle” projects:

  • Resilience — Pipeline builds can “survive” Jenkins restarts.

  • Pausable / Parameterizable — Pipeline builds can be stopped at any stage while waiting for user input. There is also a possibility to control Pipeline jobs execution through Jenkins API.

  • Power and Flexibility — Pipeline builds can have complex logic, conditional actions, be executed on multiple agents in parallel, integrate with other jobs, etc. Pipelines are defined using Groovy-based DSL so Jenkins and Java APIs can be used to define the job.

  • VCS Friendliness — As a Groovy script, Pipeline definition code can be put under a version control system. It can even be loaded from there on the fly during the Jenkins job execution, which is great for import/export/changes tracking and experimentation.

In today’s article you will learn about the ways of adding a JMeter test to a Pipeline project and see some code examples and demos.

This chapter assumes that you already have a working build step with executed JMeter tests against your application. If not, check out Continuous Integration 101: How to Run JMeter With Jenkins for an overview and setup instructions. If you have a Jenkins job which runs a JMeter test and it’s called “JMeter - Freestyle”, you can run it from Pipeline as simple as:  build job: 'JMeter - Freestyle' 

The full Pipeline code will look something like:

node {
   stage 'Build Application'
   // do what you need to do to build your application
   echo 'Compilation is done'
   stage 'Deploy Application'
   // do what you need to do to deploy your application
   echo 'Deploy is done'
   stage 'Execute JMeter Performance Tests'
   build job: 'JMeter - Freestyle'
}


jenkins jmeter pipeline

Basically, the above Pipeline configuration just triggers a predefined “JMeter - Freestyle” Jenkins Job as a part of the Pipeline build, and reports elapsed time, success, and some logs via Pipeline Dashboard.

jenkins jmeter pipeline

Specifying Build Parameters

If your existing job is parameterized the parameters can be passed via Pipeline as well like:

node {
   stage 'Execute JMeter Performance Tests'
   build job: 'JMeter - Freestyle', parameters: [[$class: 'StringParameterValue', name: 'VirtualUsers', value: '100']]
}

Given the Groovy-based nature of Pipeline projects, you can start any process using Groovy syntax. Jenkins in turn provides some short-hand variables to make it easier. For example you can use sh command for Unix-based systems or bat command for Windows systems in order to kick off a shell script (JMeter startup scripts are usual shell scripts). See Basic Groovy Syntax for Pipeline Configuration Jenkins manual chapter for more details.

The Pipeline stage to run a command-line based JMeter test, will look as simple as:

node {
   stage 'Run JMeter Test'
   bat 'c:/jmeter/bin/jmeter.bat -n -t c:/jmeter/extras/Test.jmx -l test.jtl'
}

The output would be similar, however in this case logging information will be available in the “Run JMeter Test” stage directly.

jenkins jmeter pipeline output

Publishing Build Artifacts

By default, Pipeline builds doesn’t publish anything to the build dashboard. You will need to manually specify what needs to be stored, in order for results to be accessed by yourself, team members, stakeholders, etc., directly through the Jenkins web interface.

To tell Jenkins to publish i.e. JMeter .jtl results file(s) once the build finishes, you need to add the following line to your Pipeline configuration: step([$class: 'ArtifactArchiver', artifacts: '**/*.jtl']) 

Or if you need to store jmeter.log file as well for later analysis: step([$class: 'ArtifactArchiver', artifacts: '**/*.jtl, **/jmeter.log'])

Once you add this step you should be able to seea  “General Build Step -> Archiving Artifacts” log message, .jtl result, and jmeter.log files in your build dashboard.

jenkins jmeter pipeline configuration

Using 3rd-Party Build Tools (Ant, Maven, etc.)

Running a JMeter test via command-line is not the only option. JMeter tests can also be executed using Ant Task, Maven Plugin, Gradle Plugin, etc.

Being an ultimate continuous integration tool, Jenkins supports the aforementioned build tools out-of-the-box. You can install and configure them at the Global Tools Configuration page: Jenkins -> Manage Jenkins -> Global Tool Configuration

jenkins global tool configuration

In this guide I will use Apache Ant as example. Instructions for other build systems should be similar. If you take a look at the “extras” folder of your JMeter installation, you’ll find a build.xml file sample Ant script, which is used for executing Test.jmx and converting the resulting file into HTML format using XSL templates, so you will be able to get HTML report directly on the Jenkins dashboard.

Let’s see what the associated Pipeline configuration will look like:

  • ● First of all, we need to switch Jenkins workspace to the JMeter’s “extras” folder, as Ant build file is assumed to be launched from there and result files will be stored there as well. In Jenkins Pipeline it can be done using ws command like:

  • ws('c:\\jmeter\\extras') {
       //do what you need to do here
    }


    • Second, we need to get Ant tool location from Jenkins. It can be done by using a tool command like:  def antHome = tool 'ant'  Now we have the antHome variable which resolves into the location of the Ant build tool.

    • Third and fourth: we need to run the test and publish the results. This has already been covered in previous chapter. Putting it all together, the final Pipeline code will look like:

    node {
       ws('c:\\jmeter\\extras') {
           stage 'Run JMeter Test with Apache Ant'
           def antHome = tool 'ant'
           bat "pushd c:\\jmeter\\extras && ${antHome}\\bin\\ant -f build.xml"
           step([$class: 'ArtifactArchiver', artifacts: 'Test.html', fingerprint: true])
       }
    }


    When you start the build Jenkins will invoke Apache Ant through the Pipeline code and publish the resulting “Test.html” artifact to the build dashboard.

    jenkins jmeter pipeline ant

    I believe this article will help you to get started with Jenkins Pipeline and you will be able to integrate your performance tests into your Continuous Delivery process more easily and smoothly. If anything remains unclear — don’t hesitate to ask questions using the comments!

    Reference Material:

    ● Getting Started with Pipeline

    ● Pipeline as Code with Jenkins

    ● Pipeline Tutorial

    Pipeline (software) Jenkins (software) Testing Continuous Integration/Deployment

    Published at DZone with permission of Dmitri Tikhanski, DZone MVB. See the original article here.

    Opinions expressed by DZone contributors are their own.

    Related

    • Implementing CI/CD Pipelines With Jenkins and Docker
    • Pipeline as a Service: How To Test Pipelines in GitLab
    • Getting Started With Jenkins
    • Test Automation: Maven Profiles and Parallelization in Azure Pipelines Using IaaS

    Partner Resources

    ×

    Comments
    Oops! Something Went Wrong

    The likes didn't load as expected. Please refresh the page and try again.

    ABOUT US

    • About DZone
    • Support and feedback
    • Community research
    • Sitemap

    ADVERTISE

    • Advertise with DZone

    CONTRIBUTE ON DZONE

    • Article Submission Guidelines
    • Become a Contributor
    • Core Program
    • Visit the Writers' Zone

    LEGAL

    • Terms of Service
    • Privacy Policy

    CONTACT US

    • 3343 Perimeter Hill Drive
    • Suite 100
    • Nashville, TN 37211
    • support@dzone.com

    Let's be friends:

    Likes
    There are no likes...yet! 👀
    Be the first to like this post!
    It looks like you're not logged in.
    Sign in to see who liked this post!