默認情況下fabric配置參數warn_only=False,即run指令得到的程序結束返回值不爲0則引發異常,退出後續的部署。
參考一下代碼,有兩種方式設置warn_only=True,可實現出錯後能繼續向下執行
def deploy():
with settings(
warn_only=True
):
run("ls /zz| grep ccc| grep -v fdsfds")
print "111"
run("ls /zz", warn_only=True)
print "222"
輸出參考
D:\code\devops\trunk>fab -f test.py deploy
[] Executing task 'deploy'
[127.0.0.1:22] run: ls /zz| grep ccc| grep -v fdsfds
[127.0.0.1:22] out: ls: cannot access /zz: No such file or directory
[127.0.0.1:22] out:
Warning: run() received nonzero return code 1 while executing 'ls /zz| grep ccc| grep -v fdsfds'!
111
[127.0.0.1:22] run: ls /zz
[127.0.0.1:22] out: ls: cannot access /zz: No such file or directory
[127.0.0.1:22] out:
Warning: run() received nonzero return code 2 while executing 'ls /zz'!
222
Done.
Disconnecting from 127.0.0.1:22... done.