Jenkins config for distributed runs
Quote from ljunggren on November 18, 2020, 8:22 pmSince Boozang version 5.11.x, we support distributed test runs. On test execution, Boozang can distribute work over a set of worker nodes. Use this to setup parallel test runs to reduce execution times considerably. We still support parallelization using GNU parallel or parallelization done on the Pipeline level. Nevertheless, using the new distribution feature allows for several advantages, such as the better distribution of tasks and better monitoring. Also, as we will see, it's much easier to setup.
In this forum post, I will outline the example config for Jenkins, but it should be very similar for any CI platform.
Start by defining a Jenkins job (in our example called "Distributed run"), and make sure that the job can accept the String parameters:
- "workers": number of workers
- "test": the id comprised of module id and test id delimited by a "/"
In the Build section, make sure the job has the following "Execute shell" step:
echo Running $workers processes for test: $test echo Cleanup logs and report files rm -rf *.out rm -rf *.log rm -rf *.json rm -rf *.html rm -rf *.png BASE=http://staging-be.boozang.com TOKEN=xxxxxxxxxxxxx ENV=4 PROJECT=5e3f275e64f84941a326d4d8 BRANCH=ci44 SELF=0 echo Setting up slaves counter=1 while [ $counter -lt $workers ] do echo $counter ((counter++)) WORKER_URL="${BASE}/extension?token=${TOKEN}&env=${ENV}&key=${counter}&self=${SELF}#${PROJECT}/${BRANCH}" nohup docker run --rm -v "$(pwd):/var/boozang/" --name=bzworker${counter} styrman/boozang-runner "${WORKER_URL}" > out_${counter}.log & done echo All slaves done. Starting master job. MASTER_URL="${BASE}/extension?token=${TOKEN}&env=${ENV}&key=1&self=${SELF}#${PROJECT}/${BRANCH}/${test}/run" echo ${MASTER_URL} docker run --rm -v "$(pwd):/var/boozang/" --name=bzworker1 styrman/boozang-runner "${MASTER_URL}"
This job can now be executed stand-alone or used in a Jenkins pipeline. Below is an example Pipeline configuration that has the following four stages.
- Health: Checks for health. Single test, so no need for parallelization.
- Cleanup: Cleanup test data. This stage has four separate scenarios, so benefiting from a maximum of four workers.
- Setup: Single test, so no need for parallelization.
- Smoke: Runs the whole smoke test suite with 40+ scenarios so benefits of as many workers as we can spare.
To build this Pipeline in Jenkins, create a new Pipeline job in Jenkins, and in the "Pipeline" section, pick "Pipeline script". Input the following
pipeline { agent any stages { stage("Health tests: Checks if environment available.") { steps { echo "Running health tests" build job: 'Distributed', parameters: [[$class: 'StringParameterValue', name: 'workers', value: '1'], [$class: 'StringParameterValue', name: 'test', value: 'm84/t2']] } } stage("Cleanup: Cleanup all data") { steps { echo "Running clean-up" build job: 'Distributed', parameters: [[$class: 'StringParameterValue', name: 'workers', value: '4'], [$class: 'StringParameterValue', name: 'test', value: 'm80/t3']] } } stage("Seed tests: Setup test data") { steps { echo "Running seed tests" build job: 'Distributed', parameters: [[$class: 'StringParameterValue', name: 'workers', value: '1'], [$class: 'StringParameterValue', name: 'test', value: 'm91/t2']] } } stage("Smoke tests: Tests high-priority work-flows tagged with smoke suite.") { steps { echo "Running smoke tests" build job: 'Distributed', parameters: [[$class: 'StringParameterValue', name: 'workers', value: '4'], [$class: 'StringParameterValue', name: 'test', value: 'm71/t1']] } } } }
Below is an example run of the "Pipeline suite" pipeline using Jenkins plugin "Blue Ocean".
Good luck!
Since Boozang version 5.11.x, we support distributed test runs. On test execution, Boozang can distribute work over a set of worker nodes. Use this to setup parallel test runs to reduce execution times considerably. We still support parallelization using GNU parallel or parallelization done on the Pipeline level. Nevertheless, using the new distribution feature allows for several advantages, such as the better distribution of tasks and better monitoring. Also, as we will see, it's much easier to setup.
In this forum post, I will outline the example config for Jenkins, but it should be very similar for any CI platform.
Start by defining a Jenkins job (in our example called "Distributed run"), and make sure that the job can accept the String parameters:
- "workers": number of workers
- "test": the id comprised of module id and test id delimited by a "/"
In the Build section, make sure the job has the following "Execute shell" step:
echo Running $workers processes for test: $test echo Cleanup logs and report files rm -rf *.out rm -rf *.log rm -rf *.json rm -rf *.html rm -rf *.png BASE=http://staging-be.boozang.com TOKEN=xxxxxxxxxxxxx ENV=4 PROJECT=5e3f275e64f84941a326d4d8 BRANCH=ci44 SELF=0 echo Setting up slaves counter=1 while [ $counter -lt $workers ] do echo $counter ((counter++)) WORKER_URL="${BASE}/extension?token=${TOKEN}&env=${ENV}&key=${counter}&self=${SELF}#${PROJECT}/${BRANCH}" nohup docker run --rm -v "$(pwd):/var/boozang/" --name=bzworker${counter} styrman/boozang-runner "${WORKER_URL}" > out_${counter}.log & done echo All slaves done. Starting master job. MASTER_URL="${BASE}/extension?token=${TOKEN}&env=${ENV}&key=1&self=${SELF}#${PROJECT}/${BRANCH}/${test}/run" echo ${MASTER_URL} docker run --rm -v "$(pwd):/var/boozang/" --name=bzworker1 styrman/boozang-runner "${MASTER_URL}"
This job can now be executed stand-alone or used in a Jenkins pipeline. Below is an example Pipeline configuration that has the following four stages.
- Health: Checks for health. Single test, so no need for parallelization.
- Cleanup: Cleanup test data. This stage has four separate scenarios, so benefiting from a maximum of four workers.
- Setup: Single test, so no need for parallelization.
- Smoke: Runs the whole smoke test suite with 40+ scenarios so benefits of as many workers as we can spare.
To build this Pipeline in Jenkins, create a new Pipeline job in Jenkins, and in the "Pipeline" section, pick "Pipeline script". Input the following
pipeline { agent any stages { stage("Health tests: Checks if environment available.") { steps { echo "Running health tests" build job: 'Distributed', parameters: [[$class: 'StringParameterValue', name: 'workers', value: '1'], [$class: 'StringParameterValue', name: 'test', value: 'm84/t2']] } } stage("Cleanup: Cleanup all data") { steps { echo "Running clean-up" build job: 'Distributed', parameters: [[$class: 'StringParameterValue', name: 'workers', value: '4'], [$class: 'StringParameterValue', name: 'test', value: 'm80/t3']] } } stage("Seed tests: Setup test data") { steps { echo "Running seed tests" build job: 'Distributed', parameters: [[$class: 'StringParameterValue', name: 'workers', value: '1'], [$class: 'StringParameterValue', name: 'test', value: 'm91/t2']] } } stage("Smoke tests: Tests high-priority work-flows tagged with smoke suite.") { steps { echo "Running smoke tests" build job: 'Distributed', parameters: [[$class: 'StringParameterValue', name: 'workers', value: '4'], [$class: 'StringParameterValue', name: 'test', value: 'm71/t1']] } } } }
Below is an example run of the "Pipeline suite" pipeline using Jenkins plugin "Blue Ocean".
Good luck!
Quote from ljunggren on December 9, 2020, 9:24 pmI have seen some examples where multiple Jenkins jobs running simultaneously are affecting each other. You can easily remedy this by making sure each job runs all it's slave in a unique group (this does not have to be set in the IDE - it can be free-form). Below is an example of this
echo Running $workers processes for test: $test echo Cleanup logs and report files rm -rf *.out rm -rf *.log rm -rf *.json rm -rf *.html rm -rf *.png BASE=http://staging-be.boozang.com TOKEN=xxxxxxxxxxxxx ENV=4 PROJECT=5e3f275e64f84941a326d4d8 BRANCH=ci44 SELF=0 GROUP=${BUILD_NUMBER} echo Setting up slaves counter=1 while [ $counter -lt $workers ] do echo $counter ((counter++)) WORKER_URL="${BASE}/extension?token=${TOKEN}&env=${ENV}&key=${counter}&group=${GROUP}&self=${SELF}#${PROJECT}/${BRANCH}" nohup docker run --rm -v "$(pwd):/var/boozang/" --name=bzworker${counter} styrman/boozang-runner "${WORKER_URL}" > out_${counter}.log & done echo All slaves done. Starting master job. MASTER_URL="${BASE}/extension?token=${TOKEN}&env=${ENV}&key=1&group=${GROUP}&self=${SELF}#${PROJECT}/${BRANCH}/${test}/run" echo ${MASTER_URL} docker run --rm -v "$(pwd):/var/boozang/" --name=bzworker1 styrman/boozang-runner "${MASTER_URL}"
I have seen some examples where multiple Jenkins jobs running simultaneously are affecting each other. You can easily remedy this by making sure each job runs all it's slave in a unique group (this does not have to be set in the IDE - it can be free-form). Below is an example of this
echo Running $workers processes for test: $test echo Cleanup logs and report files rm -rf *.out rm -rf *.log rm -rf *.json rm -rf *.html rm -rf *.png BASE=http://staging-be.boozang.com TOKEN=xxxxxxxxxxxxx ENV=4 PROJECT=5e3f275e64f84941a326d4d8 BRANCH=ci44 SELF=0 GROUP=${BUILD_NUMBER} echo Setting up slaves counter=1 while [ $counter -lt $workers ] do echo $counter ((counter++)) WORKER_URL="${BASE}/extension?token=${TOKEN}&env=${ENV}&key=${counter}&group=${GROUP}&self=${SELF}#${PROJECT}/${BRANCH}" nohup docker run --rm -v "$(pwd):/var/boozang/" --name=bzworker${counter} styrman/boozang-runner "${WORKER_URL}" > out_${counter}.log & done echo All slaves done. Starting master job. MASTER_URL="${BASE}/extension?token=${TOKEN}&env=${ENV}&key=1&group=${GROUP}&self=${SELF}#${PROJECT}/${BRANCH}/${test}/run" echo ${MASTER_URL} docker run --rm -v "$(pwd):/var/boozang/" --name=bzworker1 styrman/boozang-runner "${MASTER_URL}"