简体   繁体   English

如何中止XCode Bot构建?

[英]How to abort XCode Bot build?

I have a problem with Xcode bots. 我对Xcode机器人有问题。 I'm able to compile, test and archive my project, but I would like to use external tool that checks if I did code review for last commits. 我能够编译,测试和存档我的项目,但是我想使用外部工具来检查我是否对最后的提交进行了代码审查。 I would like to be able to abort build if there is no code review. 如果没有代码审查,我希望能够中止构建。 I tried to add exit 1 or exit 0 in pre-build script but it just ends given script not whole building process. 我试图在pre-build脚本中添加exit 1exit 0 ,但它只是在给定脚本(而不是整个构建过程)的情况下结束。 So my question is how I can abort Xcode bot build (integration)? 所以我的问题是如何终止Xcode bot的构建(集成)?

Technically, it is possible. 从技术上讲,这是可能的。 You can cancel an integration, which immediately aborts it. 您可以取消集成,该集成将立即终止。 It's a very similar process to triggering an integration from the command line, which I described here , but you would first need to find out the _id of the integration by calling using the endpoint /xcode/api/bots/BOT_ID/integrations and the first integration should be the latest. 这与从命令行触发集成非常相似,我在此介绍了该过程 ,但是您首先需要使用端点/xcode/api/bots/BOT_ID/integrations调用来找出集成的_id 。集成应该是最新的。 Copy the _id and then call a POST on /xcode/api/integrations/INTEGRATION_ID/cancel , which will cancel the integration. 复制_id ,然后在/xcode/api/integrations/INTEGRATION_ID/cancel上调用POST,这将取消集成。

I use all these APIs in my tool Buildasaur , so check out the source code for more details. 我在工具Buildasaur中使用了所有这些API,因此请查看源代码以获取更多详细信息。

Thanks to czechboy's answer, here is a solution for copy & paste friends. 感谢czechboy的回答,这是复制和粘贴朋友的解决方案。 Use something like this as pre-integration script: 使用以下内容作为预集成脚本:

#!/bin/sh

# something returning an error code like:
${XCS_PRIMARY_REPO_DIR}/customPreIntegrationConfiguration.sh

# if script exits with error code 1:
if (( $? )); then
    echo "canceling integration ${XCS_INTEGRATION_ID}..."
    curl -kX POST "https://localhost:20343/api/integrations/${XCS_INTEGRATION_ID}/cancel"
fi

$? checks the exit code of the last command, in this case the script. 检查最后一个命令的退出代码,在这种情况下为脚本。 If you are using a pipe somewhere, it can be necessary to use set -o pipefail to return 1 if only one pipe component returns 1. 如果在某处使用管道,则只有一个管道组件返回1时,可能有必要使用set -o pipefail返回1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM