Forum

Forum Navigation
You need to log in to create posts and topics.

Running parallel tests using Jenkins pipelines

In this topic we discuss how to run parallel test using Jenkins pipelines. There are a number of ways to run parallel tests in Boozang, but here we utilize Jenkins pipelines for the job. We'll take a step-by-step approach to make sure everything is working on the way.

Note: The following screenshots from Jenkins is using the plugin "Blue Ocean", which makes pipeline visualizations significantly prettier. 

A simple parallel pipeline

Let's look at the following basic Jenkins pipeline

pipeline {
    agent none
    stages {
        stage('run-parallel-branches') {
          steps {
            parallel(
              a: {
                echo "This is branch a"
                sleep 10
                echo "End branch a"
              },
              b: {
                echo "This is branch b"
                sleep 15
                echo "End branch b"
              }
            )
          }
        }
        /* .. snip .. */
    }
}

Make sure that when you run the job, you'll see two parallel runs happening.

This job should take about 15 seconds to complete. Depending if you run Jenkins as a single instance or using slave machines how this is handled might vary slightly. That's why it's good to take a step-by-step approach, making sure it's working correctly. 

Introducing Docker

The Boozang test runner is based on Docker, so before introducing real tests it's good to verify that Docker containers can be run in parallel as well. Instead of using the Boozang runner container, we use a vanilla container for CentOS. 

pipeline {
   agent {
        docker { image 'centos' }
    }
    stages {
        stage('run-parallel-branches') {
          steps {
            parallel(
              a: {
                echo "This is branch a using Docker"
                sh 'docker run centos sleep 10'
                echo "End branch a"
              },
              b: {
                echo "This is branch b using Docker"
                sh 'docker run centos sleep 20'
                echo "End branch b"
              }
            )
          }
        }
        /* .. snip .. */
    }
}

As you can see, we simple ask the Docker containers to sleep 10 and 20 seconds each, to clearly show that the processes are run in parallel. 

 

 

Try Boozang today

Codeless testing that works. No credit card or commitment required.