Table of contents
1.
Introduction
2.
Jenkins
3.
Jenkins Integration in Postman
4.
Postman with Newman and Jenkins
4.1.
Jenkins Setup and run
4.2.
Generating Newman reports
5.
Configuring Newman for Jenkins
6.
Frequently Asked Questions
6.1.
What is a Freestyle project in Jenkins?
6.2.
What is the difference between continuous delivery and continuous deployment?
6.3.
What is a Postman API key, and how to generate it?
7.
Conclusion
Last Updated: Mar 27, 2024

Integrating with Jenkins in Postman

Author Yashesvinee V
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Postman supports integration with a wide range of DevOps tools. These integrations can help automate various tasks that facilitate API projects. Jenkins is one such DevOps tool, an open-source automation server that acts as a Continuous Integration or Continuous delivery hub. It can be used to build, automate and deploy almost every project. Jenkins pipeline can be configured to run API tests in Postman Newman. 

Jenkins

The Jenkins DevOps tool helps automate the overall delivery pipeline of a project. Its centralised platform can automate the complete build pipeline, from code creation to auto-deploying a successful build. There are a large number of plugins available for Jenkins. The prime advantage of Jenkins is that it provides CI/CD and continuous deployment. It can automate UI Tests, Performance Tests, Integration Tests, and API Tests. Continuous delivery is the step after continuous integration. Here, all code changes are automatically built and tested to be released into an environment without any intervention from the developer. The developer only decides to trigger the live production environment.

Jenkins Integration in Postman

Integrating  Jenkins for an API in Postman requires the creation of an API token. To generate a Jenkins API token:

Step 1: Sign in to Jenkins, click on your username and select Configure.

Step 2: Click on Add new token.

Jenkins API token generation

Step 3: Enter a token name and click on Generate.

Configure Jenkins integration for an API by selecting it from the APIs section in the sidebar. Note that each API version can link to a separate CI project. So choose the API with the required version.

Step 1: Select Jenkins under Connect to CI/CD Builds in the Test tab.

Jenkins Integration

Step 2: Enter a name for the integration and the URL to a Jenkins server.

Step 3: Enter your Jenkins username. Enter the generated API token as the Authentication token.

Step 4: Select the CI project for the API and click on  Connect.

Jenkins Connection

All information about build jobs is listed under CI/CD Builds in the Test tab.

Postman with Newman and Jenkins

Newman is a command-line Collection Runner that enables users to test and run Postman Collections. It is extensible and can be integrated with continuous integration servers. Using Newman, users can also run Postman collections with the API tests as part of a Jenkins pipeline. Let us see how to set up a Jenkins build that uses Newman for a Collection run. In this case, Jenkins will run locally, and the build will be marked successful only if the collection passes all the tests.

Jenkins Setup and run

Step 1: Install Jenkins and start it locally.

Step 2: Install Node.js and Newman in Jenkins. 

Step 3: Go to Manage Jenkins > Manage Plugins and install the NodeJS plugin in the Jenkins server.

Step 4: Select Add NodeJS under NodeJS in Manage Jenkins > Global Tool Configuration.

Step 5: Give a name for the installation.

Step 6: Enter “Newman” in Global npm packages to install. Click on Save.

Step 7: Export a ready-to-run Postman collection as a JSON file.

Step 8: Create a new job by clicking on New Item in the Jenkins dashboard on the local server.

Step 9:  Select a Freestyle Project and give it a name.

Step 10: Go to General > Build and add a build step in the project. Choose Execute Shell and enter a shell command to run the collection.

newman run ~/Desktop/jenkins_postman_collection.json

Step 11: Under Build Environment, click on Provide Node & npm bin/ folder to PATH and choose the installed NodeJS configured with Newman.

Generating Newman reports

Analysing results and console output logs can be quite difficult and tedious. Jenkins plugin offers solutions to generate rebuild results as graphical reports for easy understanding. Jenkin plugins can also give a detailed overview of the entire build process. Newman also has a few report-generating commands.

CLI and JUNIT reporters are used to generate Newman reports in Jenkins. The report generating command is attached at the end of the run command in Newman.

newman run <Collection> --reporters cli,junit

Users can also specify a path to store the Newman report on Jenkins. The command for this is

newman run <Collection> --reporters cli,junit -reporter-junit-export "newman/myreport.xml"

Users can view XML results generated by Newman under the Workspace folder.

To publish HTML reports, we require the HTML publisher Plugin in Jenkins. It can be found under Manage Jenkins > Manage Plugins. We can generate HTML reports by adding “– reporters html” to the run command. To export the HTML report, add “--reporter-html-export :"newman/myHTMLreport.html".

Configuring Newman for Jenkins

To configure Newman for Jenkins, generate the Newman configuration code in Postman and add it to the Jenkins pipeline.

Step 1:Select View Builds under CI/CD Builds in the Test tab. Click on Configure Newman.

Step 2: Select a collection to run and copy the Newman configuration code. Click on Finish.

Step 3: Open the pipeline project in Jenkins and go to Configure.

Step 4: Paste the copied Newman configuration code as the Pipeline script. Enter the code with the proper NodeJS tool name and valid Postman API key.

Step 5: Click Save and run the pipeline with the new configuration.

Frequently Asked Questions

What is a Freestyle project in Jenkins?

A freestyle project can run any build, including shell scripts, dos scripts, etc. It can be used to perform build server work like continuous builds and perform tests or repetitive batch tasks. Freestyle projects are very flexible and can work with the majority of plugins in Jenkins.

What is the difference between continuous delivery and continuous deployment?

Continuous delivery requires manual approval to update to production, while continuous deployment does it automatically without approval. In continuous deployment, the code is pushed for without involving the developer.

What is a Postman API key, and how to generate it?

A Postman API key is required to send requests to the Postman API. The Postman API keys page can be displayed by going to Settings > Postman API keys. Users can generate an API key if they do not have one by giving a name for the key and clicking on Generate API key.

Conclusion

This blog discusses the integration of Postman with Jenkins. It briefly explains the use of Jenkins to run pipelines and how to use it with Postman and Newman to perform collection runs. We also covered how to configure Newman for Jenkins and generate Newman reports. Check out our articles on Run in PostmanScripts in Postman and Using Collection runner in Postman. Explore our Library on Coding Ninjas Studio to gain knowledge on Data Structures and Algorithms, Machine Learning, Deep Learning, Cloud Computing and many more! Test your coding skills by solving our test series and participating in the contests hosted on Coding Ninjas Studio! 

Looking for questions from tech giants like Amazon, Microsoft, Uber, etc.? Look at the problems, interview experiences, and interview bundle for placement preparations. Upvote our blogs if you find them insightful and engaging! Happy Coding!

Thank you Image

Live masterclass