Jenkins Declarative Pipeline – how to display Gatling results?

What I would like to do is for Jenkins to display the HTML report produced by a Gatling simulation somewhere there around the Job page.

I’m using the Declarative Pipeline syntax and running Gatling in a docker container.

  • You're accessing the development server over HTTPS, but it only supports HTTP when using Docker
  • Docker doesn't persist created file
  • Docker Container fails to connect to remote SQL
  • Unable to pull google/appengine-go docker image
  • ansible_default_ipv4.address undefined in docker ubuntu
  • Swarm: Manager in host + Worker in VM: No containers in workers
  • Here is the code:

                sh '''docker run -i -d --net=host --name gatlingAG ubuntu
                      docker cp gatling gatlingAG:/
                      docker exec gatlingAG apt-get -qq update
                      docker exec gatlingAG apt-get -qq install default-jdk
                      docker exec gatlingAG /bin/bash -c "./gatling/bin/gatling.sh -m"'''
    

    After the simulation is finished, the results are created in TestResults/[name_of_simulation] folder within the docker container.

    I can’t seem to find a way on the internet to reach that folder, and the index.html file inside, to display the results in Jenkins. How to do that?

  • Docker: Devices cgroup isn’t mounted (Ubuntu 16.04)
  • How to access docker daemon from container with other user than root
  • Adding config file in docker run command
  • Running GUI from a container on a mac resolve in “libGL error: No matching fbConfigs or visuals found”
  • Does Kubernetes evenly distribute across an ec2 cluster?
  • RabbitMQ Cluster does not elect new master
  • One Solution collect form web for “Jenkins Declarative Pipeline – how to display Gatling results?”

    Firstly just a quick word on using Docker:

    Where Docker shines is when you use it to build immutable infrastructure i.e. Containers that don’t change. To that end, Docker supports the Dockerfile which allows you to build up containers via a number of different steps such as installing Gatling and also setting the default command to be run in the container when it starts.

    By using the Dockerfile approach, you could build a Gatling container that you use for your tests, and that would free you up from having to run the docker exec gatlingAG apt-get -qq update type statements each time your pipeline runs in Jenkins. Just something to consider.

    Now onto your problem of archiving the output of Gatling via your Jenkins pipeline. There are two ways that you can approach this:

    1. Use docker cp to copy the results back out of the container into the Jenkins workspace for your pipeline
    2. Mount the workspace into the Gatling container, so that results are written directly to the workspace and can be easily archived

    1: Using docker cp

    You already use docker cp to copy things into the container, so you can just use that to copy things back out again after Gatling has run. You could do something like this:

    sh '''docker run -i -d --net=host --name gatlingAG ubuntu
                  docker cp gatling gatlingAG:/
                  docker exec gatlingAG apt-get -qq update
                  docker exec gatlingAG apt-get -qq install default-jdk
                  docker exec gatlingAG /bin/bash -c "./gatling/bin/gatling.sh -m"'''
                  docker cp gatlingAG:/gatling/[name_of_run] . 
    

    That would copy the output from the container filesystem to your workspace filesystem, from where you can archive it (see bottom of the answer).

    2: Mounting the Jenkins workspace into the container

    Docker supports mounting filesystems from the host machine into any containers that run on it. By doing that, processes within the container can write files onto more reliable storage or storage that outlasts the life of the container (as soon as you destroy a container its filesystem is lost forever)

    Again you could do something like this with your pipeline definition:

    sh '''docker run -i -d --net=host -v $(pwd)/gatling:/gatling --name gatlingAG ubuntu
                  docker exec gatlingAG apt-get -qq update
                  docker exec gatlingAG apt-get -qq install default-jdk
                  docker exec gatlingAG /bin/bash -c "./gatling/bin/gatling.sh -m"'''
    

    You’ll notice that I’m using the -v option when running the container to tell Docker to mount the gatling directory at /gatling in your container. That means you don’t need to copy it in. Also when Gatling runs, the results will be written directly to your workspace, meaning that you can easily archive them one Gatling has finished. You may need to make sure that the results of any previous Gatling run are cleaned from the workspace before you run the pipeline again.

    Archiving the results

    Finally, once you have the output of the Gatling run in your workspace, you can simply archive it using the archive Jenkins pipeline directive. This will mean that Jenkins stores the HTML as an artifact of the job. You can then access the HTML directly via your browser e.g.

    https://jenkins-url/job/gatlin-job/1/artifact/TestResults/[name_of_simulation]/index.html

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.