我在Jenkins中使用不同的命令集(调用Execute shell测试应用程序)来使用newman函数。当其中一个测试用例通过newman失败时,我的构建被标记为失败。
前Execute shell
newman run ./test/postman_collection_1.json --environment ./test/postman_environment.json --bail
newman run ./test/postman_collection_2.json --environment ./test/postman_environment.json --bail由于我将所有这些命令移动到一个脚本文件中,并使用"Execute shell“来执行这个脚本文件(它是以前直接在"Execute shell”中的命令的副本),所以当newman测试用例失败时,我的构建不再被标记为失败。
新Execute shell:
chmod +x ./docs/ci_tests.sh
./docs/ci_tests.shci_tests.sh的内容:
#!/bin/bash
newman run ./test/postman_collection_1.json --environment ./test/postman_environment.json --bail
newman run ./test/postman_collection_2.json --environment ./test/postman_environment.json --bail为什么命令(newman)的返回值在我通过文件使用它们时不会触发jenkins失败的原因?
发布于 2017-08-16 07:10:25
当测试失败set -e时,必须将shell环境设置为退出
当此选项打开时,当任何命令失败时(由于Shell错误的后果中列出的任何原因或返回大于零的退出状态),外壳将立即退出,就像执行没有参数的退出专用内置实用程序一样,但有以下例外:多命令管道中任何单个命令的失败都不应导致外壳退出。应只考虑管道本身的故障。后执行复合列表时,应忽略-e设置,直到,如果,或elif保留字,管道以!保留字或除最后一个以外的和-或列表的任何命令。如果子shall命令以外的复合命令的退出状态是在忽略-e时失败的结果,则-e将不适用于此命令。
您可以在设置或取消设置选项和位置参数上找到有关bash选项的更多信息。
所以bash脚本应该变成
#!/bin/bash
set -e
newman run ./test/postman_collection_1.json --environment ./test/postman_environment.json --bail
newman run ./test/postman_collection_2.json --environment ./test/postman_environment.json --bailhttps://serverfault.com/questions/868820
复制相似问题