42
Integrating Newman API test collections with Jenkins and publish reports using Flock messenger
In this article, we will be exploring about how to run Postman collections on Jenkins with Freestyle Project. And we will try to generate our test run reports using Allure Jenkins plugin and will publish the test run status notifications to Flock messenger.
Before we get started, you’ll need to install Jenkins on your machine. If you don’t have a setup Jenkins on your machine please follow this official documentation.
After installing Jenkins, we need to configure NodeJS on Jenkins.
Install and restart the Jenkins for proper installation of the plugin.
Open Jenkins: Manage Jenkins → Global Tool Configuration → NodeJS
Set your compatible node version. We can set multiple NodeJS versions for multiple applications.
Make sure you follow these steps:

1. Create a Freestyle job to execute Newman collections scripts.
Open Jenkins → New Item → Enter any job name→ Choose Freestyle Project → Click on Save button
2. Parameterising the Jenkins build for different Newman environment
A build parameter allows us to pass data into our Jenkins jobs. Build parameters are a powerful way to make any Jenkins job more dynamic.So by using build parameters, we can pass any data we want. In our use case, we will be passing the Newman environment variables. Note: Follow this tutorial, If you want to get a Newman environment variables’ unique id.
A build parameter allows us to pass data into our Jenkins jobs. Build parameters are a powerful way to make any Jenkins job more dynamic.So by using build parameters, we can pass any data we want. In our use case, we will be passing the Newman environment variables. Note: Follow this tutorial, If you want to get a Newman environment variables’ unique id.
4.Build environment → Check “Delete workspace before build starts”
5.Build environment → Check “Provide Node & npm bin/ folder to PATH” → select NodeJs name

6.Build → Add build step → Select Execute Shell → And Paste the below code. → Save Your config.
eg:- newman run [collections] -e [environment] -r allure --reporter-allure-export target/allure-results --suppress-exit-code 1
newman run "https://api.getpostman.com/collections/[collection_uid]?apikey=[apiKey]" \
--environment "https://api.getpostman.com/environments/$server?apikey=[apiKey]" \
-r allure --reporter-allure-export target/allure-results \
-- suppress-exit-code 1
Note: If you want to run Newman via shell command using a unique collection id & API Key follow this tutorial.


Allure and Flock Plugin Installation
Please follow this guide to generate a Webhook URL

Now we just have to build our job to execute our tests. And we can do so by clicking on the “Build with Parameters” button on the left side of the dashboard.
Click on Build with Parameter → Select the options that are required to be passed in the branch parameter [QA/ Prod] and click on → BUILD
Flock messenger would notify you about the Jenkins build status.
To view reports click on “View” in flock → Will be redirected to Jenkins [After successful authentication]→ Click on Allure Report
In this article we have seen how to use Jenkins to run Newman tests, generate & publish reports using Allure / Flock plugins. I hope you may have found this useful. Cheers!!
42