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.
Contents
Jenkins Setup
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.
Step1: Install NodeJS plugin :
Go to → Manage Jenkins → Select Manage Plugins → Select Available tab and Search Active Choice Plugin.
Install and restart the Jenkins for proper installation of the plugin.
Step2: Add Newman and Allure Packages in NodeJS
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:
- Check the “Install automatically” option
- Select compatible Node version (NodeJs-16.2.0)
- Add required packages in the “Global Packages to Install” section In our case, add the following packages newman newman-reporter-allure
- Save settings.
Step3: Create a Newman job with freestyle.
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.
Extended Choice Parameter Plug-In Installation:
- Go to 'Manage Jenkins' from the Jenkins homepage.
- Navigate to Manage Plugins
- Change the tab to Available
- Search for extended choice parameter
- Click “Download now and install after restart”
General → Check “This project is parameterized” → Add parameter → Choice parameter → add respective choice values for parameterization [QA / Prod].
3.Source Code Management → Check “None”
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
- Go to 'Manage Jenkins' from the Jenkins homepage.
- Navigate to Manage Plugins
- Change the tab to Available
- Search for Flock and Check the box
- Search for Allure Report and Check the box
- Click “Download now and install after restart”
7.Post Build Action → Allure Report → Add Path (“target/allure-results”)
Allure Reports will be generated after every successful builds and report files are placed under the given $PATH
8.Post Build Action → Send Flock Notification (add flock webhook URL)
Please follow this guide to generate a Webhook URL
- Go to https://apps.flock.com/?source=launcherbar
- Search for Jenkins
- Install and Configure to generate webhook URL.
How to Run
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.
- Go to Jenkins Job [jenkins_url/job/[#JobName]]
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!!
Top comments (0)