【问题标题】:Using script to fire Xcode bot使用脚本触发 Xcode bot
【发布时间】:2015-04-16 15:54:49
【问题描述】:

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

【问题讨论】:

    标签: xcode osx-server xcode-bots


    【解决方案1】:

    是的。

    您需要做几件事: 首先,我将调用你的 Xcode Server 的 IP 地址 XCS_IP,如果你在运行 Xcode Server 的机器上,通常是 localhost。

    • 找出机器人的 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 是允许在服务器上创建机器人的用户的凭据,管理员会这样做。

    如果您对更多细节感兴趣,我有一个使用该 API 的 Swift 应用程序以及更多: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;博士?在您的 Mac 上,查看/Applications/Xcode.app/Contents/Developer/usr/share/xcs/xcsd/routes/routes.js,您可以在其中找到可用的 API。

    希望这会有所帮助。

    【讨论】:

    • 只是添加 - 它是使用 node.js 编写的。
    • 从 Xcode7 beta5 开始,routes.js 也被分割成单独的文件。
    • @Eimantas 是的,在 Xcode 7 中略有变化,但要点是相同的。实际上,我编写了一个 CLI 工具来快速完成其中一些事情:github.com/czechboy0/xcskarel
    【解决方案2】:

    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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-04
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 2015-01-10
      • 2016-02-05
      • 2019-08-10
      • 2015-04-21
      相关资源
      最近更新 更多