LoginSignup
43

More than 5 years have passed since last update.

GitLab CIでXcodeプロジェクトをCIする手順

Last updated at Posted at 2016-02-26

GitLab CIでXcodeのユニットテストを自動実行した際の手順です。
Xcodeプロジェクトの設定 以外はiOSに依存しない内容です。

バージョン

ツールおよび OS は以下のバージョンを使用しました。
GitLab 8.5
Xcode 7.2.1
OS X 10.11.2(ビルドマシン)

GitLabでCIを有効化

自動ビルドの設定

  1. project を選択 -> 左ペイン左下の Settings から CI/CD Pipelines 画面に移動。
  2. 下記 ランナーの設定 手順を行い、ブラウザをリロードすると、設定したランナーが表示されるので Enable for this project ボタンを選択し、ランナーを有効にします。

ランナーの設定

1. ビルドマシンに GitLab CI Multi-Runner をインストール

$ sudo curl --output /usr/local/bin/gitlab-ci-multi-runner https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-ci-multi-runner-darwin-amd64

2. 実行権限の付与

$ sudo chmod +x /usr/local/bin/gitlab-ci-multi-runner

3. ランナーの設定

$ gitlab-ci-multi-runner register
  • URL, トークンの入力を求められますが、GitLabの以下に表示される値を使用します。
  • GitLab -> 任意nprojectを選択 -> Settings(歯車のマーク) -> Runners
  • executor としては今回 shell を選択しておきます。

4. ランナーのインストール、起動

$ cd ~
$ gitlab-ci-multi-runner install
$ gitlab-ci-multi-runner start
  • この時、 register, install, start を同じユーザで実行しないとランナーが正しく起動しないので注意します。

5. 確認

正しく設定ができていれば、GitLab上でランナーのステータスがグリーンになります。
green.png

Xcodeプロジェクトの設定

スキームの作成

  1. プロジェクトの Manage Schemes メニューを選択し、CI でビルドしたいプロジェクトの shared にチェックをしておきます。
  2. プロジェクトファイルの直下に {project_name}.xcodeproj/xcshareddataというディレクトリができるので、忘れずにgit commitします。

manage_schemes.png

shared.png

以下のコマンドで scheme が登録されていることを確認できます。

# ワークスペースの場合
$ xcodebuild -workspace <ワークスペース名>.xcworkspace -list

# プロジェクトの場合
$ xcodebuild -project <プロジェクト名>.xcodeproj -list

.gitlab-ci.yml

  1. .gitlab-ci.yml をリポジトリのルートに追加。
  2. リポジトリにファイルがプッシュされたタイミングで実施したいコマンドを yaml に記載します。

今回は、リポジトリからプロジェクトをクローンし、ユニットテストを実行するだけです。

gitlab-ci.yml
test:
  script:
    - export LANG=en_US.UTF-8
    - xcodebuild test -workspace <workspace-name>.xcworkspace -scheme <scheme-name> -destination 'platform=iOS Simulator,OS=9.2,name=iPhone 6s'

ビルド

以上で一通りの手順が完了しました。リポジトリにコミットがプッシュされる度に、上記の yaml に記載したコマンドが実行されます。

configuration_done.png

参考URL

GitLab CI Quick Start
http://doc.gitlab.com/ce/ci/quick_start/README.html

GitLab CI Multi Runnerのインストール
https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/install/osx.md

Automating the Test Process
https://developer.apple.com/library/tvos/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/08-automation.html

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
43