使用脚本触发Xcode机器人。

4
有没有一种通过shell脚本手动触发现有的Xcode Bot的方法?我有一个手动Bot,希望能基于某些自定义逻辑标准来触发它。
2个回答

18

是的。

您需要执行一些操作:

首先,我将呼叫您的Xcode服务器IP地址为 XCS_IP,在您运行Xcode服务器的机器上通常为本地主机。
  • 查找机器人的ID:在终端中运行 curl -k "https://XCS_IP:20343/api/bots"。将输出复制到某个编辑器中,并找到机器人的键值_id的值,将类似于6b3de48352a8126ce7e08ecf85093613。我们称之为BOT_ID

  • 通过运行curl -k -X POST -u "username:password" "https://XCS_IP:20343/api/bots/BOT_ID/integrations" -i来触发整合。

其中usernamepassword是允许在服务器上创建机器人的用户的凭据,管理员会执行。

如果您对更多详细信息感兴趣,我有一个Swift应用程序使用了该API和更多内容:https://github.com/czechboy0/Buildasaur/blob/master/BuildaCIServer/XcodeServer.swift#L324

并查看我的文章,了解如何找到Xcode服务器的API“文档”:http://honzadvorsky.com/blog/2015/5/4/under-the-hood-of-xcode-server

总之,在Mac上,查看/Applications/Xcode.app/Contents/Developer/usr/share/xcs/xcsd/routes/routes.js,您可以找到可用的API。

希望这有所帮助。


只是补充一下 - 它使用 node.js 编写。 - Eimantas
从Xcode7 beta5开始,routes.js已被拆分为单独的文件。 - Eimantas
1
@Eimantas 是的,在 Xcode 7 中有些变化,但基本思路是相同的。实际上,我编写了一个 CLI 工具,可以快速完成其中一些操作:https://github.com/czechboy0/xcskarel - czechboy

1
苹果已经添加了 Xcode 服务器 API 的文档,您可以使用它来触发机器人。

https://developer.apple.com/library/tvos/documentation/Xcode/Conceptual/XcodeServerAPIReference/index.html#//apple_ref/doc/uid/TP40016472-CH1-SW1

以下是一些示例代码,展示如何编写一个Python脚本来触发一个机器人。
import requests

xcodeIP = '1.2.3.4.5'

def main():
    botName = "name of bot"
    runBot(botName)

def runBot(botName):
    requests.post(xcodeIP + '/api/bots/' + getBot(botName)["_id"] + '/integrations', auth=('username', 'password'), verify=False)

def getBot(botName):
    botIDRequest = requests.get(xcodeIP + '/api/bots', auth=('username', 'password'), verify=False)
    bots = botIDRequest.json()["results"]
    for bot in bots:
        if bot["name"] == botName:
            return bot

if __name__ == "__main__":
    main()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接