使用脚本来解雇Xcode bot

时间:2015-04-16 15:54:49

标签: xcode osx-server xcode-bots

有没有办法使用shell脚本手动触发现有的Xcode机器人?我有一个手动机器人,我想根据某些自定义逻辑标准来启动它。

2 个答案:

答案 0 :(得分:17)

是。

您需要做以下几件事: 首先,我要打电话给您的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 Server的API"文档":http://honzadvorsky.com/blog/2015/5/4/under-the-hood-of-xcode-server

TL; DR?在Mac上,查看/Applications/Xcode.app/Contents/Developer/usr/share/xcs/xcsd/routes/routes.js,您可以在其中找到可用的API。

希望这会有所帮助。

答案 1 :(得分:1)

Apple已添加了可用于触发机器人的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()