【问题标题】:How to fail a AppCenter build on script exit code?如何在脚本退出代码上构建 AppCenter 失败?
【发布时间】:2020-02-20 23:16:40
【问题描述】:

我有一堆脚本在调用 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

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

任何人都有这方面的经验和/或知道如何通过他们的脚本使 AppCenter 构建失败?提前感谢您的想法!

【问题讨论】:

  • 据我所知,非零状态代码应该可以解决问题。将运行并通知您!
  • 感谢您的检查。我也是这么想的。

标签: ios swift continuous-integration cd visual-studio-app-center


【解决方案1】:

好的,想通了。看起来像使用环境变量“$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"

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

【讨论】:

    猜你喜欢
    • 2019-05-02
    • 1970-01-01
    • 2017-10-20
    • 2022-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-19
    • 1970-01-01
    相关资源
    最近更新 更多