即使上传到托管平台的代码检索到错误,Gitlab作业仍然成功

时间:2019-04-05 10:42:07

标签: gitlab gitlab-ci continuous-deployment

我有一个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有时会过期,然后我们需要一个新的$ 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

当我收到此类错误时,有什么方法可以变得更聪明并使工作失败?

谢谢!

1 个答案:

答案 0 :(得分:2)

为了将作业标识为失败,脚本需要返回非零的退出状态。

因此,在您的upload_build_to_facebook脚本中,您需要检查上传是否成功。如果不是,则应该执行exit 1