【问题标题】:Custom Trigger Scripts for Bot (Xcode 5 CI)机器人的自定义触发脚本(Xcode 5 CI)
【发布时间】:2013-11-28 12:10:37
【问题描述】:

我正在为我的 iOS 应用程序设置 CI,但遇到了一些问题。

  • 在哪里可以找到关于 Bot 的文档的好地方?我看过 Xcode 帮助但找不到任何好的例子,还观看了来自的 CI 视频 2013年会议
  • 如何创建自定义触发脚本,所以每次开发人员 提交他们的代码,它会自动触发机器人。
  • 只有在测试成功通过的情况下,如何将代码合并到 master 机器人?

在这里我找到了有关触发脚本的信息 https://help.apple.com/xcode/mac/1.0/#apdE6540C63-ADB5-4B07-89B7-6223EC40B59C

每个设置都显示了示例值。时间表:选择运行 手动、定期、新提交或触发脚本

谢谢!

【问题讨论】:

    标签: continuous-integration xcode5 xcode-bots


    【解决方案1】:

    Apple 开发者网站上有一个Continuous Integration Guide,它提供了有关如何设置 CI 构建的详细说明。但是,它缺少有关触发脚本的详细信息。

    为此,最好的文档可以在 OSX Server 脚本本身中找到。 Apple 在此处使用的术语“触发脚本”指的是 Git 中的 post-receive 挂钩。 Git 事件挂钩可以添加到任何 Git 存储库的 .git/hooks 子目录中,以执行操作以响应包含它们的 Git 存储库上的事件。

    要查看专门“启动”Xcode 服务以运行 CI 构建的示例 post-receive 挂钩,请在托管 Xcode 构建服务的服务器上创建托管 Git 存储库。默认情况下,添加到 Xcode 服务器的 Git 存储库将自动创建一个接收后挂钩。在这种情况下,它是一个 Ruby 脚本,其中 POSTs 到 http://localhost/xcs/kick-commit-botsrepositorybranch 表单字段设置为存储库的 URL(因为它在 Xcode 服务中配置)和分支分别拉.

    因此,按照 Xcode 持续集成指南中概述的步骤创建一个托管存储库,然后在 Xcode 服务器上查看 /Library/Server/Xcode/Repositories/git/<your project>.git/hooks/post-receive 的内容。如果您在其他地方托管您的 Git 项目(例如 BitBucket、GitHub 或本地网络上的 linux 机器),您可以在使用您选择的脚本语言创建自己的接收后挂钩时使用此文件作为指南。

    对于那些无法在其构建服务器上创建托管存储库的用户的示例:

    #!/usr/bin/env ruby
    
    ##
    # Copyright (c) 2014 Apple Inc. All Rights Reserved.
    #
    # IMPORTANT NOTE: This file is licensed only for use on Apple-branded
    # computers and is subject to the terms and conditions of the Apple Software
    # License Agreement accompanying the package this file is a part of.
    # You may not port this file to another platform without Apple's written consent.
    #
    # IMPORTANT NOTE: This file is licensed only for use with the Wiki Server feature
    # of the Apple Software and is subject to the terms and conditions of the Apple
    # Software License Agreement accompanying the package this file is part of.
    ##
    
    # fill in the exact URL to your repository, as entered in your OS X Server configuration
    $repository_url = "file:///git/python-lrparser.git"
    $repository_mode = "git"
    
    # fill in the hostname of your OS X Server machine; this must be accessible by the server
    # on which your repository is hosted; you may use "localhost" for the local machine
    #server_host = "server.example.com"
    $server_host = "localhost"
    
    
    ##########################################
    ## DO NOT EDIT BELOW THIS LINE
    ##########################################
    
    require 'net/http'
    
    def kick(branch)
      theURL = URI("http://#{$server_host}/xcs/kick-commit-bots")
      if branch.nil?
        Net::HTTP.post_form(theURL, 'repository' => $repository_url)
      else
        Net::HTTP.post_form(theURL, 'repository' => $repository_url, 'branch' => branch)
      end
    end
    
    if __FILE__ == $0
      # determine what branch this is a push to, if possible
      branches = []
    
      if $repository_mode == "git"
        $stdin.each_line do |line|
          oldrev, newrev, ref = line.strip.split
          if ref =~ %r{^refs/heads/(.+)$}
            branches.push($~[1])
          end
        end
      elsif $repository_mode == "svn" and ARGV.length >= 2
        repository = ARGV[0]
        revision = ARGV[1]
        modifiedDirs = `svnlook dirs-changed -r #{revision} #{repository}`.lines.map { |line| line.chomp }
        modifiedDirs.each do |d|
          if d =~ %r{branches/([^/]+)}
            branches.push($~[1])
          end
        end
      end
    
      # if we have no branch information, just kick generically
      puts "Notifying OS X Server..."
      if branches.empty?
        kick(nil)
      else
        # otherwise, do a targeted kick for each relevant branch
        branches.each do |branch|
          kick(branch)
        end
      end
    end
    

    【讨论】:

      【解决方案2】:

      在机器人的方案中,创建一个解析测试结果的构建后脚本。

      测试结果将位于此处:

      /Library/Server/Xcode/Data/BotRuns/Latest/output/xcodebuild_result.bundle/Info.plist
      

      一旦您验证了该 plist 中的测试通过,您就可以合并到 master。

      然后创建一个仅在有人推送到 master 时才集成的机器人。我相信编辑机器人的时间表可以选择轮询回购以进行更改。确保机器人是由当前在 master 上的 Xcode 项目创建的。

      当 Xcode 位于您要创建的测试分支上时,需要创建第一个机器人。

      【讨论】:

        猜你喜欢
        • 2016-05-29
        • 1970-01-01
        • 2013-11-02
        • 2018-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多