Running Postman collections in Jenkins as a part of CI/CD

Aytac Tas
3 min readNov 22, 2020

In this article, I would like to demonstrate how Postman can be used as an automation framework in CI/CD pipelines running on a Jenkins.

We are going to use containerized versions of Jenkins and Newman. Newman is the CLI version of Postman. We’re gonna have to apply “Docker in Docker” approach to run Newman container inside of Jenkins container.

The volume mechanism on Docker will persist data and we are going to use that for two purposes. First, to be able to run the docker container in another docker container (docker.sock will do that job) and second, to be able to send postman collections into Docker container.

So, we need to define the path on the host machine so that container can retrieve the data from there (Of course we need to put the postman collection we want to run into that path). After the colon, we need to add the container path which is the part we want to target on the container.

-v ${host_machine_path}:${container_path}

Step 1: First of all, we install a docker image for Jenkins from dockerhub. We should customize our Jenkins image so that it can mount the host machines’s docker socket to Jenkins container. We also should install docker ce into our container. In order to do that, we are going to build an image by extending official Jenkins image as below:

FROM jenkins/jenkins:ltsUSER rootRUN apt-get update -qq && apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
RUN apt-get update && apt-get install docker-ce=17.12.1~ce-0~debian -y
RUN usermod -aG docker jenkins

Only thing you need to do, is creating a Dockerfile, then run the following command on the same path to build an image:

docker build . -t my_customized_jenkins:latest

Step 2: Run the image to create a container:

docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock my_customized_jenkins:latest

Once the installation is finished and set up is done, we’re gonna have a Jenkins server on our local, up and running.

Step 3: As a final step, we create a job for running Postman collections within a container by navigating to the “New Item” section. The only thing we need to do is to add the following command on the “Execute Shell” field.

docker run -v path_on_host:/etc/newman -t postman/newman run "test_postman_collection.json"

Here we are! We can run Postman collections with Jenkins containers as a part of CI/CD.

--

--