有蘋果開發者網站提供的如何設置你的CI構建詳細的解釋上可用的Continuous Integration Guide。它缺少關於觸發器腳本的細節。
對於最好的文檔在OSX服務器腳本本身找到。此處Apple使用的術語「觸發器腳本」指的是Git中的post-receive hooks。可以將Git事件掛鉤添加到任何Git存儲庫的.git/hooks子目錄中,以執行操作以響應包含它們的Git存儲庫上的事件。
要查看示例後收到掛鉤,特別是「踢」的Xcode的服務運行CI構建,創建主機您的Xcode構建服務的服務器上託管Git倉庫。默認情況下,添加到Xcode服務器的Git存儲庫會自動創建後接收掛鉤。在這種情況下它是一個Ruby腳本POST
s至http://localhost/xcs/kick-commit-bots
與repository
和branch
設置到存儲庫的URL(因爲它是在Xcode服務配置)表單字段和分支分別拉哪個。
因此,請按照Xcode持續集成指南中列出的步驟創建託管存儲庫,然後在Xcode服務器上查看/Library/Server/Xcode/Repositories/git/<your project>.git/hooks/post-receive
的內容。如果您將Git項目託管在其他地方(例如BitBucket,GitHub或本地網絡上的一個Linux機器),您可以使用該文件作爲指導,以您選擇的腳本語言創建自己的post-receive hook。
對於那些沒有自己的生成服務器上創建一個託管回購的選擇誰舉個例子:
#!/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