Hi folks, In this brief blog post, we’ll learn more about Gitlab CI and Postman, the API testing tool we use the most frequently. This article’s goal is to provide a quick process for automatically testing the service API response. The solution makes use of the capabilities provided by the Gitlab-integrated Continuous Integration tool.
Introduction to Gitlab CICD
GitLab CI/CD is a continuous integration (CI) and continuous delivery (CD) service that’s integrated with GitLab SaaS and self-managed. Software development teams can use GitLab CI/CD to automatically build, test, and deploy code in GitLab.
Why do we integrate Gitlab CICD with the postman?
Continuous integration(CI) has its own component in Gitlab. Gitlab is able to execute a pipeline of scripts to build, test, and validate the code modifications for each change that is submitted. In this situation, the CI will focus on automatically executing the requests in the extracted Postman Collection and assessing the outcomes of each test. The outcome of the test will have an impact on each job’s status. I believed that all the question are cleared now so let’s moves toward how we create our CICD pipeline.
Demonstrating how we create a CICD pipeline
For your benefit, let’s divide the process into several steps.
Step1: Create and add a project to the Gitlab Repository

Now we have a project as per our basic requirements. Let’s move towards the second step.
Step2: Add Postman sample collection to Gitlab repository
Add the sample postman collection along with the collection Environment in the form of a JSON file as given below



Ok, now that we have the prerequisites clear, let’s get back to our basic topic.
Step3: How should a GitLab pipeline be defined?
Therefore, if you already have a repository along with data, you may skip the previous two steps, but you still need to add a new file inside the repository called.gitlab-ci.yml. This file will serve as the Gitlab pipeline definition. postman/newman_alpine33.
So, under this.gitlab-ci.yml file, we will define a new test stage, and we will create a new job called postman_tests and assign it to the test stage. Of course, it is entirely up to you what names you give the tasks and phases.
Where do we use Newman in the pipeline and Why?
Newman is a command-line agent that allows you to run multiple requests sequentially. Newman will use an official Docker image named “The Docker Images,” which includes <strong>Newman</strong>, named <strong><code>postman/newman</code> </strong>The Docker images with include Newman, are created and constantly updated by the Postman Team. So this is why I always prefer to use official and maintained Docker images instead of relying on 3rd parties or building my own.
After we include the image, the first step is to check if Newman is properly working. The easiest way to check that is by running newman
--verisa-quick-overview-how-to-run-postman-test-with-newman-in-gitlab-cion



As you can see, we try to define the pipeline by adding 9-10 lines to a the.gitlab-ci.yml file, and after committing the changes, this file is reflected in our branch.



Let’s explore more about the.gitlab-ci.yml file, Under each stage, we define what we do, like deploying, testing, and executing the data. After that, we need to define the name of the job. In our scenario, we have postman_test for a particular stage test. As you know, we test the Postman collection with the help of Newman, so we have a docker image like postman/newman_alpine33. To execute this Docker image, Newman and Docker publish some entry points. Finally, I define an empty entry point. Finally, we have a script in which we pass commands to run the postman collection.
But Gitlab requires some small validation To use free CI/CD minutes on shared runners, you’ll need to validate your account with a credit card.



Once you have verified your account or created a new one, you will get the below output.



Now the pipeline is declared and it is working as expected, so let’s run the postman test collection with the help of Newman.



After committing the changes, the pipeline gets active and provides output as failed or passed based on the data you passed.
Conclusion
In this short blog, we learned how to kickstart the Postman test with Gitlab using Newman. In our upcoming posts, we will go into greater detail on this.
Till then, Happy learning, happy sharing!
You may also click on these simple links to learn more about this integration here.
1 thought on “How To Run Postman Test With Newman In Gitlab Ci5 min read”
Comments are closed.