Running Postman Collections In Jenkins from a Git Repo

1.2k views Asked by At

I am trying to run my Postman collections, which are in a git repo, through Jenkins pipeline job, but I get the error -->> sh: newman: command not found

Steps:

  1. Export collections from Postman
  2. Push these to a Git repo.
  3. Run these collections in Jenkins

Contents of package.json in the project:-

{
   "name":"tests",
   "version":"1.0.0",
   "description":"tests",
   "directories":{
      "tests":"PostmanCollection",
      "environments":"PostmanEnvironment"
   },
   "scripts":{
      "test123":"newman run PostmanCollection/wms_int_b.json --folder Automated -e PostmanEnvironment/Local.postman_environment.json -k --reporters junit"
   },
   "repository":{
      "type":"git",
      "url":"[email protected]:test.git"
   },
   "author":"AB",
   "dependencies":{
      "newman":"^5.2.0",
      "npm":"^6.14.8"
   }
}

Jenkins pipeline script from jenkinsfile:

pipeline{
    agent { label 'build' }

    stages {
        stage('Run API Tests') {
            steps {
                sh 'npm run test123'
            }
        }
    }
}

enter image description here

Any suggestions would be really helpful. I believe its got to do with Node.js as Newman needs it. Some people have suggested I need to run this in a docker, but I have no idea how to configure it.

1

There are 1 answers

0
John On

Install newman in jenkins Try this

pipeline{ agent { label 'build' }

stages {
    stage('Run API Tests') {
        steps {
            sh 'npm install -g newman'
            sh 'npm run test123'
        }
    }
}

}