我有一个 Gitlab CI/CD 管道,可将代码上传到 Facebook 托管平台。
这是舞台:
upload:production:
stage: upload
before_script:
- source ci/upload.sh
only:
- master
script:
- upload_build_to_facebook production $GAME_ID_PRODUCTION $UPLOAD_ACCESS_TOKEN_PRODUCTION
environment:
name: production
url: https://developers.facebook.com/apps/$GAME_ID_PRODUCTION/instant-games/hosting
尽管作业成功完成,但 $UPLOAD_ACCESS_TOKEN_PRODUCTION 有时会过期,然后我们需要一个新的:
{"error":{"message":"An unexpected error has occurred. Please retry your request later.","type":"OAuthException","is_transient":true,"code":2,"fbtrace_id":"<id>"}}Job succeeded
当我收到这种错误时,有什么方法可以更聪明地让工作失败吗?
谢谢!
最佳答案
为了将作业识别为失败,脚本需要返回非零退出状态。
因此,在您的 upload_build_to_facebook
脚本中,您需要检查上传是否成功。如果没有,您应该exit 1
。
关于即使代码上传到托管平台检索到错误,Gitlab 作业也会成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55533644/