我正在尝试使用 HTML 报告器安装和运行 Postman 的 Newman 测试集合(在带有来自 Postman 帐户的 docker 图像的 jenkins podTemplate 容器上)但它一直失败,因为找不到合适的 Newman 版本:
"npm WARN newman-reporter-htmlextra@1.19.6 requires a peer of newman@>=4 but none is installed. You must install peer dependencies yourself"
Newman 镜像 docker 是“postman/newman:5.2-alpine”。
运行命令是
sh "newman run tests/collection.json -r htmlextra --reporter-htmlextra-export var/reports/newman/html/index.html";
我也尝试过安装(“sh”前缀是因为它在 groovy 脚本中..在 Jenkins 中):
sh "npm install -g newman@4.6.1"
sh "npm install -g newman-reporter-htmlextra"
然后执行与上面相同的运行命令。
sh "newman run tests/collection.json -r htmlextra --reporter-htmlextra-export var/reports/newman/html/index.html";
但结果是一样的。
奇怪的是,在我收到上面提到的错误之后 - jenkinsfile 执行了“newman run”命令并成功创建了测试报告文件:
Using htmlextra version 1.19.6
Created the htmlextra report in this location: var/reports/newman/html/index.html
但随后以 FAILURE 退出脚本/作业。
我错过了什么? 有什么建议吗?
谢谢!
答案 0 :(得分:2)
这是一个 npm 错误,https://github.com/npm/npm/issues/12905
对于 newman-reporter-htmlextra ,newman 是对等依赖。
在 npm 中,如果依赖项和包没有一起安装,则不会检测到全局包的对等依赖项
在这种情况下,您可以使用
一起安装来修复它npm install -g newman newman-reporter-htmlextra
试试:
podTemplate(label: "newmanPodHtmlExtra", containers: [
containerTemplate(name: "newman", image: "dannydainton/htmlextra", command: "cat", ttyEnabled: true),
]) {
node("newmanPodHtmlExtra") {
def testsFolder = "./tests";
container("newman") {
stage("Checkout") {
checkout scm;
}
try{
stage("Install & run Newman") {
sh "npm install -g newman newman-reporter-htmlextra";
sh "newman run ${testsFolder}/collection.json -r htmlextra --reporter-htmlextra-export var/reports/newman/html/index.html";
}
}catch(e){}finally{
stage("Show tests results") {
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'var/reports/newman/html', reportFiles: 'index.html', reportName: 'API Tests', reportTitles: ''
])
}
}
}
}
}