Rahul Bagale
Rahul Bagale

Reputation: 1

newman the cli companion for postman not work with URL in azure pipeline

Configuration :

- task: NewmanPostman@4
        inputs:
          collectionSourceType: 'url'
          collectionURL: 'https://api.getpostman.com/collections/{collectionId}?apikey={apiKey}'
          environmentSourceType: 'url'
          environmentUrl: 'https://api.postman.com/environments/{enviormentId}?apikey={apiKey}'
          reporters: 'htmlextra'
          pathToNewman: '/opt/hostedtoolcache/node/18.15.0/x64/bin/newman'
          htmlExtraDarkTheme: true
          htmlExtraReportTitle: 'ExploreFunctionalTestSummary'
          reporterHtmlExport: '$(Pipeline.Workspace)/drop/Postman'
          verbose: true
          logLevel: detailed
          sslInsecure: false

Error : throwing issue ##[error]The process '/opt/hostedtoolcache/node/18.15.0/x64/bin/newman' failed with exit code 1

Debug same scenario on local system after newman install, but got collection not loading ,

Approch-1 to debug on local

error: collection could not be loaded unable to fetch data from url "*https://api.getpostman.com/collections/{collectionId}?apikey={apiKey}*"

Provide the correct approch to implement it without ollectionfile/enviormentfile

Upvotes: 0

Views: 250

Answers (1)

wade zhou - MSFT
wade zhou - MSFT

Reputation: 8478

NewMan is preinstalled on Ubuntu-latest agent, the version is 6.1.1.

As per the guide:

  1. If you would like to use a different version of newman, you can install with npm task as below:
  - task: Npm@1
    displayName: NewMan install
    inputs:
      command: 'custom'
      customCommand: 'install [email protected] -g'

For the pathToNewman parameter, it points to the newman path if you don't want to use the default version.

enter image description here

Unless you have newman installed on the path /opt/hostedtoolcache/node/18.15.0/x64/bin/newman, please remove the parameter in the task NewmanPostman@4.

  1. For the htmlextra reporter type, you need to install newman-reporter-htmlextra ahead via npm task:
  - task: Npm@1
    displayName: NewMan reporter htmlextra install
    inputs:
      command: 'custom'
      customCommand: 'install -g newman-reporter-htmlextra'

My complete yaml below, i added the comment on the tasks.

pool: 
  VMImage: Ubuntu-latest

steps:
  - script: newman --version
    
  # - task: Npm@1                             # commented as i used default Newman
  #   displayName: NewMan install
  #   inputs:
  #     command: 'custom'
  #     customCommand: 'install [email protected] -g'

  - task: Npm@1
    displayName: NewMan reporter htmlextra install
    inputs:
      command: 'custom'
      customCommand: 'install -g newman-reporter-htmlextra'
  

  - task: NewmanPostman@4
    inputs:
      collectionSourceType: 'url'
      collectionURL: 'https://api.getpostman.com/collections/$(collectionid)?apikey=$(apiKey)'
      environmentSourceType: 'url'
      environmentUrl: 'https://api.postman.com/environments/$(environmentid)?apikey=$(apiKey)'
      reporters: 'htmlextra'
      #pathToNewman: '/opt/hostedtoolcache/node/18.15.0/x64/bin/newman'    # comment it as i use default newman
      htmlExtraDarkTheme: true
      htmlExtraReportTitle: 'ExploreFunctionalTestSummary'
      # reporterHtmlExport: 'drop/Postman'             # i used default newman path for the output path
      verbose: true
      logLevel: detailed
      sslInsecure: false
  

  - task: PublishBuildArtifacts@1
    inputs:
      PathtoPublish: '$(Pipeline.Workspace)/s'
      ArtifactName: 'drop'
      publishLocation: 'Container'

enter image description here

Check the report in artifact: enter image description here

Edit: Add the variable list:

enter image description here

Upvotes: 0

Related Questions