我试图用HTML reporter安装和运行Postman的Newman测试集(在jenkins podTemplate容器上,带有Postman帐户中的docker图像),但它总是失败,因为找不到合适的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"纽曼图像码头是“邮递员/纽曼:5.2-阿尔卑斯山”。
而Run命令是
sh "newman run tests/collection.json -r htmlextra --reporter-htmlextra-export var/reports/newman/html/index.html";我还尝试使用( "sh“前缀是因为它在groovy script..in 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但随后退出脚本/作业失败。
我遗漏了什么?有什么建议吗?
谢谢!
发布于 2020-12-22 11:08:24
这是一个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: ''
])
}
}
}
}
}https://stackoverflow.com/questions/65398954
复制相似问题