Auf der Apple-Entwicklerwebsite finden Sie eine Continuous Integration Guide, die detaillierte Erklärungen zum Einrichten Ihrer CI-Builds enthält. Es fehlen jedoch Details zu Triggerskripten.
Dafür finden Sie die beste Dokumentation in den OSX Server-Skripten selbst. Der Begriff "Trigger-Skripte", wie er hier von Apple verwendet wird, bezieht sich auf Post-Receive-Hooks in Git. Git-Ereignis-Hooks können zum Unterverzeichnis .git/hooks eines beliebigen Git-Repositorys hinzugefügt werden, um Aktionen als Reaktion auf Ereignisse im Git-Repository auszuführen, das sie enthält.
Um einen Post-Receive-Hook zu sehen, der speziell einen Xcode-Dienst zum Ausführen von CI-Builds "startet", erstellen Sie ein gehostetes Git-Repository auf dem Server, auf dem Ihr Xcode-Build-Service gehostet wird. Git-Repositories, die standardmäßig einem Xcode-Server hinzugefügt werden, erhalten automatisch einen Post-Receive-Hook, der automatisch erstellt wird. In diesem Fall handelt es sich um ein Ruby-Skript, das POST
s bis http://localhost/xcs/kick-commit-bots
mit repository
und branch
Formularfeldern auf die URL des Repositorys (wie es im Xcode-Dienst konfiguriert ist) und die zu ziehende Verzweigung setzt.
Erstellen Sie ein gehostetes Repository, indem Sie die im Xcode Continuous Integration Guide beschriebenen Schritte ausführen und dann den Inhalt von /Library/Server/Xcode/Repositories/git/<your project>.git/hooks/post-receive
auf dem Xcode-Server anzeigen. Wenn Sie Ihre Git-Projekte anderswo hosten (z.BitBucket, GitHub oder eine Linux-Box in Ihrem lokalen Netzwerk) können Sie diese Datei als Leitfaden verwenden, wenn Sie in Ihrer bevorzugten Skriptsprache einen eigenen Post-Receive-Hook erstellen.
Ein Beispiel für diejenigen, die die Möglichkeit haben keine gehosteten Repo auf ihren Build-Server zu erstellen:
#!/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