Jenkins Pipeline how to run parallel tests in your workflow stages
Jenkins Pipeline is a suite of plugins that allows creating simple-to-complex build stages for your testing environment on CI. We can use Jenkins Pipeline to run a few stages at the same time and thanks to that parallelize test suite across a few stages to complete tests faster.
In order to run parallel stages with Jenkins Pipeline, we will need a proper Jenkinsfile which represents our delivery pipeline as code via the Pipeline domain-specific language (DSL) syntax.
Another thing we will have to figure out is the problem how to divide our test suite across parallel stages in a way that each subset of test suite executed across all stages will complete work at the same time. It’s important to complete the tests on all stages at a similar time to run our CI build as fast as possible and eliminate bottleneck stage.
How to split test suite evenly across parallel Jenkins stages
To divide our tests across parallel stages we can use Knapsack Pro which allows to dynamically allocate tests across stages (also known as CI nodes). This way we will run our parallelised tests in optimal time.
Here you can learn more how dynamic test suite allocation works and with what else problems it can help.
Jenkinsfile for parallel pipeline
In this example, I will show you how to split your Ruby and JavaScript tests across parallel Jenkins stages.
This is Ruby example how to split Cucumber and RSpec test suite. Other test runners like Minitest, Test::Unit etc are available as well at Knapsack Pro:
Here is JavaScript example how to split Cypress tests. You can learn more about splitting E2E tests for Cypress test runner here.
Summary
Jenkins Pipeline gets you a continuous delivery (CD) pipeline which is an automated expression of your process for getting software from version control right through to your users. It’s important to save the time of your engineering team by running CI build fast. One way of doing it is test suite parallelisation that can be done in an optimal way with Knapsack Pro for Ruby and JavaScript tests.
If you are currently considering the choice between Jenkins and other CI, check out our popular comparison pages: Jenkins vs Github Actions, Drone vs Jenkins, AWS CodeBuild vs Jenkins, and Cloud Build vs Jenkins.