问题描述
我已尝试按照 Medium 帖子中的说明将 Postman 集合集成到 Azure 中我在 newman 下运行了 Postman 测试,但是我看到错误。我已经尝试了 newman 插件和命令行任务。
解决方法
错误提示 403 ip forbidden ,这意味着您运行脚本的服务器无权访问 api
Azure App Service Deploy returns (403) Forbidden with IP restriction
参考这个答案。
关于你得到的 json 错误来自
pm.response.json()
由于响应是 html,因此无法解析。
,禁止 403 ip
根据此错误消息,您的 azure 应用似乎有 IP 限制。
您可以尝试添加 Azure PowerShell 任务来运行以下脚本,将当前 IP 添加到应用访问限制中。
示例:如果您使用的是 Azure 应用服务,则可以使用以下脚本
$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
这是关于 the detailed script 的文档。
对于 newman 测试,您已经参考了博客。所以你会得到两个 Json 文件(一个是集合,另一个是环境变量)。
您可以参考以下管道设置:
Yaml 编辑器:
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
经典编辑器: