【问题标题】:Run multiple postman collections using newman on Jenkins在 Jenkins 上使用 newman 运行多个邮递员集合
【发布时间】:2019-12-14 09:22:47
【问题描述】:
我在 Jenkins Pipeline 作业中使用以下命令:
sh "postman-combine-collections -f *.postman_collection.json -o out.collection.json"
sh "newman run out.collection.json -e apigee-${params.Environment}-environment.postman_environment.json"
它总是只运行第一个集合。
我正在使用 Postman-combine-collections v1.1.0。
提前致谢!
【问题讨论】:
标签:
jenkins-pipeline
postman
jenkins-groovy
newman
【解决方案1】:
我在尝试一次又一次地运行 newman 两次时遇到了同样的问题。我想使用两个不同的环境文件。如果 newman 退出失败(退出代码!= 0),Jenkins 作业将停止。
如果使用 -x (--suppress-exit-code),则执行第二次运行。不幸的是,这样第一次运行的退出代码设置为 0。第一次运行失败的测试不会导致 Jenkins 作业失败。
这是我的解决方案:
sh """
set +e
newman run collection.json -e environment01.json
if [ $? != 0 ]
then
newman run collection.json -e environment02.json
exit 1
else
newman run collection.json -e environment02.json
fi
"""
通过明确定义“set +e”,Jenkins 继续失败。如果第一次运行的退出代码不为零,那么无论第二次运行得到什么结果,Jenkins 都会以返回代码 1 退出。尽管两次运行都已执行。如果第一次运行成功,则第二次运行将确定 Jenkins 作业的结果。