如何使基于脚本退出代码的 AppCenter 构建失败?

Cra*_*her 3 continuous-integration cd ios swift visual-studio-app-center

我有一堆在调用 appcenter-pre-build.sh 时被调用的脚本。例如,其中之一是简单检查当前分支标签是否已存在于存储库中。

  #!/usr/bin/env bash

  set -e # Exit immediately if a command exits with a non-zero status (failure)

  # 1 Fetch tags
  git fetch --tags

  # See if the tag exists
  if git tag --list | egrep -q "^$VERSION_TAG$"
  then
    echo "Error: Found tag. Exiting."
    exit 1
  else
    git tag $VERSION_TAG
    git push origin $VERSION_TAG
  fi
Run Code Online (Sandbox Code Playgroud)

如果找到该标签,我想中止 AppCenter 中的构建并使其失败。当我通过 Xcode Server 运行所有内容时,这工作得很好,但由于某种原因,我无法弄清楚如何在脚本失败时中止构建。我没有看到太多关于这个特定主题的文档,而 Microsoft 的 AppCenter 人员正在花时间回复我。

有人有这方面的经验和/或知道如何从他们的脚本中使 AppCenter 构建失败吗?预先感谢您的想法!

Cra*_*her 5

好吧,想通了。看起来使用环境变量“$APPCENTER_BUILD_ID”发送一个curl请求来取消构建可以解决这个问题。以非零值退出脚本在 AppCenter 内不起作用。

以下是要执行的操作的示例。我只是将其放入一个特殊的“cancelAppCenterBuild.sh”脚本中,并调用它来代替我的退出。

  API_TOKEN="<YourAppToken>"
  OWNER_NAME="<YourOwnerOrOrganizationName>"
  APP_NAME="<YourAppName>"

  curl -iv "https://appcenter.ms/api/v0.1/apps/$OWNER_NAME/$APP_NAME/builds/$APPCENTER_BUILD_ID" \
  -X PATCH \
  -d "{\"status\":\"cancelling\"}" \
  --header 'Content-Type: application/json' \
  --header "X-API-Token: $API_TOKEN"
Run Code Online (Sandbox Code Playgroud)

专业提示:如果您曾经重命名过应用程序,AppCenter 服务器在引用新名称时会遇到问题。我收到了带有禁止消息的 403。您可能需要将应用程序名称更改为原始名称,或者只是在 AppCenter 中从头开始重建应用程序。