stage('python') {
sh script: '''
#!/bin/bash
set -ex
python2.7 -u run_test.py <--- this script had a import error but stage passed
'''.stripIndent()
}
在日志中,
[2021-01-09T05:35:25.812Z] + python2.7 -u run_test.py
[2021-01-09T05:35:27.183Z] Traceback (most recent call last):
[2021-01-09T05:35:27.183Z] from util.common import log
[2021-01-09T05:35:27.183Z] ImportError: No module named util.common
对于上面python失败的情况,我如何确保该阶段失败?
如果sh脚本返回非零退出状态,sh script: '''...'''
命令将抛出/使管道失败。您使用了set -ex
,因此应该会使它失败并出现第一个错误。你能修改你的脚本来显示python命令的退出状态吗?