我建议使用全局变量来保存错误消息。我的猜测是该变量在您的范围中不存在。
def FAILURE_MSG // Global Variablepipeline { ... stages { stage(... steps { container('ansible') { script { ... if (result != "") { FAILURE_MSG = FAILURE_MSG + result } } } } } post { always { script { sh "${FAILURE_MSG}" // Hint: Use correct String Interpolation } } }}


