We can write the automation test suite for any service which can be used for performing regression testing. But we can also integrate our automation test scripts using Newman in Jenkins CI/CD pipeline which can be triggered automatically whenever a pull request gets merged.
We need software installed on our system locally:
- Postman (For writing the collection)
Files for execution
- Firstly create a postman collection that is to be run using Newman and store it in a folder.
- Now check-in your collection into your git repository. We need the link to the git repository which we will use in the further steps.
Setting up Jenkins pipeline
- Now start your local jenkins with command:
systemctl start jenkins
- You can access your Jenkins dashboard using the URL
- After logging in go to new item.
- Give a name to you project, select freestyle project and click OK.
- Scroll down to Source Code Management section of the page and select git.
- Enter the link to your git repository
- If you are using an private repository you can add you credentials.
Go to buld section, click on add build step and select execute shell.
- Write the Newman command to execute your postman collection.
newman run Mycollection.postman_collection.json
- Click on save, go to your newly created project and click on ‘build now’
- Click on the running build and click on console output.
- Here we can see the result of our current test run. That how many tests failed or passed and also shows if the build is successful or not.
So this was a small introduction on how to execute postman collection with Newman in Jenkins. It is very helpful for CI/CD while development of services.