0

I have tried to integrate Postman collection in Azure as per the instructions on Medium post I have my Postman tests running under newman however i am seeing error. I have tried both the newman addon and command line tasks.

Error message

Alka
  • 163
  • 1
  • 10
  • The process 'C:\npm\prefix\newman.cmd' failed with exit code 1.I get that received html response instead of Json but the request response should be Json. – Alka Mar 04 '21 at 00:03
  • Hi @Alka. Is there any update about this ticket? Feel free to let me know if the answer could give you some help. Just a remind of [this](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work). – Kevin Lu-MSFT Mar 08 '21 at 10:01

2 Answers2

0

The error says 403 ip forbidden , it means the the server from which you are running script is not authorized to access the api

Azure App Service Deploy returns (403) Forbidden with IP restriction

Refer to this answer .

And about the json error you are getting is from

    pm.response.json()

As the response is html so it cannot be parsed .

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • 1
    Changing the agent pool to the server and installing nodejs on the server has solved the problem. – Alka Mar 11 '21 at 20:03
0

403 Ip Forbidden

Based on this error message, it seems that your azure app has IP restrictions.

You could try to add a Azure PowerShell task to run the following script to add the current IP to the app access restriction.

Example: If you are using Azure App Service, you could use the following script

$IP= Invoke-RestMethod http://ipinfo.io/json | Select -exp ip

$IP

Add-AzWebAppAccessRestrictionRule -ResourceGroupName "ResourceGroup" -WebAppName "AppName"  -Name "Ip example rule" -Priority 100 -Action Allow -IpAddress $IP

Here is a doc about the detailed script.

For the newman test, you have referenced the blog. So you will get two Json files(one is the collection, the other is the env variables).

You could refer to the following pipeline setting:

Yaml Editor:

steps:
- task: AzurePowerShell@5
  displayName: 'Azure PowerShell script: InlineScript'
  inputs:
    azureSubscription: 
    ScriptType: InlineScript
    Inline: |
     $IP= Invoke-RestMethod http://ipinfo.io/json | Select -exp ip
     
     $IP
     
     Add-AzWebAppAccessRestrictionRule -ResourceGroupName "ResourceGroup" -WebAppName "AppName"  -Name "Ip example rule" -Priority 100 -Action Allow -IpAddress $IP
    preferredAzurePowerShellVersion: 3.1.0

- script: |
   npm install -g newman
   
   
   
  displayName: 'Command Line Script'

- task: carlowahlstedt.NewmanPostman.NewmanPostman.NewmanPostman@4
  displayName: 'Newman - Postman'
  inputs:
    collectionFileSource: '$(build.sourcesdirectory)'
    Contents: 'kevintest123.postman_collection.json'
    environment: '$(build.sourcesdirectory)/test/versionenv.postman_environment.json'
    ignoreRedirect: false
    bail: false
    sslInsecure: false
    htmlExtraDarkTheme: false
    htmlExtraLogs: false
    htmlExtraTestPaging: false

Classic editor:

enter image description here

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28