Newman Collection postman json - pipeline Azure Devops

486 Views Asked by At

Can anyone tell me how to configure path of node and npm in my pipeline in Azure Devops as variable env sustem, to make make newman run my collection postman json?

I created a pipeline but it does not execute my collection MyCollection is pushed in my repo, in Azure Devops

1

There are 1 best solutions below

2
wade zhou - MSFT On

As per the newman guide, you need to have Node.js >= v16 installed on the machine, the easiest way to install Newman is using NPM. On DevOps Microsoft-hosted agent, it has Node and NPM preinstalled already, you don't need to configure path of node and npm.

Microsoft-hosted agents: windows-2022 as sample below: enter image description here

Step1: Just simply run npm install -g newman to install Newman globally(-g for globally), it allows you to run it from anywhere.

Step2: You can upload the collection.json to DevOps git repo, and specify the json file for the newman command.

DevOps yaml sample:

- script: |
   npm install -g newman
   
  workingDirectory: '$(System.DefaultWorkingDirectory)'
  displayName: 'Command Line Script'

- script: 'newman run TEST.postman_collection.json --reporters cli,junit --reporter-junit-export Results\junitReport.xml '
  workingDirectory: '$(build.sourcesdirectory)'
  displayName: 'Command Line Script

In addition, there is an extension Newman the cli Companion for Postman, you can use it to run the newman command as well.

steps:
- script: |
   npm install -g newman
  workingDirectory: '$(System.DefaultWorkingDirectory)'
  displayName: 'Command Line Script'


- task: NewmanPostman@4
  displayName: 'Newman - Postman'
  inputs:
    collectionFileSource: 'TEST.postman_collection.json'
    environmentSourceType: none
    ignoreRedirect: false
    bail: false
    sslInsecure: false
    htmlExtraDarkTheme: false
    htmlExtraLogs: false
    htmlExtraTestPaging: false

You can check similar link for your reference.

PS: If you use self-hosted agent, you can pre-install the node.js and NPM, system variable should have configured, the DevOps agent can automatically scan them(capability), and invoke them in the task.