POSTMAN with Jenkins

POSTMAN requests and tests can be run in different ways. One of the ways is to run tests directly from the POSTMAN interface by writing scripts and there are other ways is to run the test using frameworks such as Newman and Jenkins.

In our previous article, we have seen how to run a collection from the command line using Newman and npm. Now let us see how to run the POSTMAN test using Jenkins.

What is Jenkins?

Jenkins is a continuous integration tool written in Java and is an open-source tool. It can be used as a continuous integration server to performs a chain of different actions leading to an integration process.

This is a server-based application and requires a web server like Apache or Tomcat. The popularity of Jenkins lies in the fact that all the faults and errors can be detected at the early stages of software development. Jenkins achieves this by letting you continuously test your build project and find the error in the early stages of development.

Why Companies are Using Jenkins?

Some of the reasons are below:

  • Software companies can accelerate their software development process as Jenkins helps us to build automated tests at a very good rate.
  • Not only at the software final development phase, but Jenkins can also be used at all the phases of the software development life cycle.
  • Even in the stages like documentation also Jenkins can helpful.
Advantages of using Jenkins

There are different advantages of using Jenkins, some are stated below:

  • As Jenkins is an open-source, therefore there are different inputs that are taken from the public through various public meetings to make the project and the strategies better.
  • Due to the high and frequent engagement of people, every month the Jenkins team is able to make a stable release.
  • There are more than 350 Plugins which can be directly accessed from the Jenkins Database.
  • Jenkins supports cloud-based architecture which makes it possible to deploy Jenkins in cloud-based platforms.
Disadvantages of Using Jenkins

There are disadvantages of using Jenkins, though it is powerful and of the most widely tool. Some of them are:

  • The installation is process is a bit harder and thus developers find it difficult to get started with it. Those who are working with it for the first time, have issues even to configure it after installation.
  • Despite the fact that it is a continuous integration tool, the continuous integration fails suddenly when even a minor change is carried out in the settings, etc.
  • The interface used by Jenkins looks obsolete, but it is not really known why the interface developers are not taking measures to upgrade it.
What is meant by Continous Integration?

When a particular task is completed by a developer working in the software development phase, then he/she can commit the code when completed. Now, when there are many developers working on the same project, they may need to commit multiple times in a given time. And also the commit time for all the developers may be different.

Now, when someone completes his piece of work, then he makes a code commit. After the commit, the build starts, then the test is started and then the deployment starts. So basically we can see that it goes like this: code commit->build->test->deploy.

This process keeps on rotating for all the individual developers until the project is completed. This process is called continuous integration.

The continuous integration process includes hosting, monitoring, compiling, testing code, etc. And so tools necessary are:

  • Continuous Integration Servers such as Jenkins, TeamCity, etc.
  • Source Control Tool such as CVS, GIT, etc.
  • Build Tools such as Make, ANT, Maven, etc.
  • Automation Testing Framework such as Selenium, Appium, UTF, etc.
Jenkins Plugins

Jenkins will allow you only to use some set of a limited set of features. If Jenkins has to be integrated with other tools then there are plugins that need to be installed. Suppose, if you want to integrate your Jenkins with GIT then the GIT plugins have to be installed.

Installing Jenkins and Getting Started

To run a test from Jenkins, we see the two following things:

  • How to setup job in Jenkins.
  • How to run POSTMAN from Jenkins.

Before you start using Jenkins, the Jenkins software must be installed in your system.

Download Jenkins: Visit the official page of Jenkins: https://jenkins.io/download/

postman-jenkins-installation-page

Now, click and download the .war file. (for windows users).

Once the file gets downloaded, just create any folder on the desktop(optional) and move the jenkins.war file into that folder.

I have named my folder as jenkins.(you may use any name.). Now open the command prompt and change the path to the same jenkins folder directory.

postman-cmd-jenkins-folder

Now, type the following command: java -jar jenkins.war.

Now, you should see that the jenkins set-up has started in the command prompt itself.

postman-jenkins-setup-started

The above way may not work every time while installing Jenkins. The other way to install Jenkins is by directly using the Jenkins Installer where you will be asked whether you want to download and install necessary plugins at the same time of installing the software.

visit the link: https://jenkins.io/download/ and hit the download button as shown in the below interface.

postman-jenkins-download-page

The Jenkins file which you will download will be a .rar file and you have to extract it.

postman-jenkins-rar-file

Now, you will get the actual file, which you can start installing directly into your system.

postman-jenkins-install-options

Once you click Install, you will be asked to proceed to the installation by clicking Next.

postman-jenkins-install-next

After clicking Next button, the installation process for Jenkins will start. Sometime, it may ask for selecting additional plugins and sometime it may install the required plugins by default.

Once Jenkins gets installed, you will see this interface after setting a username and a password. Jenkins will open in any of your chosen browsers and by default, it will load in the address: localhost:8080. Just make sure that the port 8080 is not used by any other applications or thread in your Operating system.

postman-jenkins-interface

Running Test with Jenkins

To run a test using Jenkins, the collection which you want to run has to be exported into a local directory of the system. Let us choose a collection and export it.

Go to POSTMAN and select the collection you want to export. Click into the three dot(...) sign beside the collection name and you will find an option to export the collection.

postman-export-option

Once you select the export option, you will get some options on which files you want to export. There will a POSTMAN recommended one. You should choose that.

postman-recomend-export-collection

After selecting the radio button Collection v2.1 (which is the recommended one), click the Export Button.

postman-save-exported-collection

You may choose any directory, I have chosen the folder collection, which I have created inside the C drive. And save the file with any file name. But the extension should be .json.

Once you save the file in the folder or directory, you are done with exporting. Now, go to your browser and load Jenkins. By default, your Jenkins should load into the PORT 8080, so type localhost:8080 into the URL bar and hit enter.

Now, once the page is loaded into your browser, you should see the page as below:

postman-jenkins-interface

In the above image, you can see the welcome message from Jenkins and below that there is an option for create new jobs. Click to create new jobs to get started.

postman-jenkins-new-job-option

Now, enter any name of your choice. I shall name it as: testjob.

postman-jenkins-freestyle-project

Then click on the Ok button which in on the same page to save the job.

postman-jenkins-okay-button

Once you click the Ok button, the job will be instantly saved and you will see the job configuration page.

postman-jenkins-configuration-page

As you scroll down the page you will be navigated to the Build option.

postman-jenkins-ad-build-step

In the case you are using windows, select the Execute Windows batch command. In the case you are using Mac, select the Execute shell command.

postman-jenkins-command-editing

Now, inside the while textarea, you can write the same Newman command, which you wrote in case of running the POSTMAN test in the command line, using Newman.

The steps to run the test would be: