Part 2

In my last project, I had to get back to using Jenkins. Other than a few years ago, I wanted to use it in a containerized environment this time. Also, I wanted to automatically run integration tests once the unit testing was completed and successful.

When it comes to integration testing, I like to use Robotframework. It is easy to get used to, and due to its Python integration, you can do almost anything with it. So, the task at hand was to create an agent docker container that is able to run Robotframework based tests. This is the Dockerfile that I used for this purpose:

FROM openjdk:8u232-jdk
 
RUN apt-get update
RUN apt-get install -y python3
RUN apt-get install -y python3-pip
RUN pip3 install robotframework
RUN pip3 install robotframework-requests
RUN pip3 install robotframework-jsonlibrary
 
LABEL maintainer="markus.schneider@plexx.digital"

As you can see, I am making sure that Python3 is installed, and I also need pip3 to then install the actual framework along with two relevant libraries (one for making HTTP requests, one for JSON processing). Based on the above Dockerfile, you can then create the robot-helper image:

docker build -t robot-helper .

Now you can use this in your Jenkinsfile for the integration test stage in the pipeline:

{
    ...
    stage('Integration Test') {
        agent {
            docker {
                image 'docker.plexx.digital/robot-helper'
                registryUrl 'https://docker.plexx.digital'
                registryCredentialsId 'plexx_docker_registry'
            }
        }
        steps {
            sh './jenkins/scripts/run_integration_tests.sh'
        }
    }
    ...
}

Above snippet is just an extract from my pipeline definition. You will have to adjust this to meet your own requirements and environment. I am maintaining a private docker registry. For this, I am keeping access credentials in Jenkins (see the registryUrl and registryCredentialsId settings).

Whenever someone from the team checks in a new version of the project, Jenkins will pick it up, compile it, run the unit tests, pack everything up and then run the Robotframework based integration tests.