在 Bash 脚本中,如何退出整个脚本并 return 成功

In a Bash script, how can I exit the entire script and return the success

我正在编写 jenkins 作业并在单个作业中添加了多个 shell。在某些情况下,在一个 shell 我想成功终止脚本并且不执行其他 shells.

我尝试使用 exit 0 -> Job Success 但它正在执行其他 shells。 出口 1 对我不起作用,因为它导致作业失败。

您可以创建包装器脚本,它将一个接一个地执行您的所有脚本。并在执行特定脚本后检查 return 代码是否为 0,如果是,则退出此包装脚本。类似于:

#!/bin/bash
/path/to/script1
/path/to/script2
#script3 is this in question
/path/to/script3
if [ $? -eq 0 ]
then exit 0
else /path/to/script4
fi

考虑使用管道。 groovy 脚本有 throw/catch 功能。