(今回はArchiveまでを行ってみます。IPA出力は今回は割愛します。) また、この記事では事前にUnity側でTeam IDを設定していることを想定しています。 (Developer Programに入っている必要があります)
下記のSigning Team Idにわすれず入力しておきましょう

ビルド実行用のメソッドを叩けるようにしておく必要があります。
下記クラスをAssets/EditorにBatchBuild.csを作成しておきましょう。
Assets/Editorでなくても良いですが、必ずEditorディレクトリ配下に作成しておきます。
あ、Unityのプロジェクトはgithubに存在している想定です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
using UnityEngine; using UnityEditor; using System.IO; using System.Linq; using System.Collections; public static class BatchBuild { // 出力先 private const string OutputDir = "Builds/"; // 生成名 private const string Android = "out.apk"; private const string IOS = "XcodeProject"; private static BuildOptions buildOptions = BuildOptions.Development; [MenuItem("Build Android")] private static void BuildAndroid() { var scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(); string path = GetOutputPath(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // 出力用のファイルを定義 var outputFile = path + Android; if (File.Exists(outputFile)) { File.Delete(outputFile); } var target = BuildTarget.Android; BuildPipeline.BuildPlayer(scenes, outputFile, target, buildOptions); } [MenuItem("Build iOS")] private static void BuildiOS() { var scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(); string path = GetOutputPath(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // 出力用のフォルダを設定 var outputFile = path + IOS; if (Directory.Exists(outputFile)) { Directory.Delete(outputFile, true); } var target = BuildTarget.iOS; BuildPipeline.BuildPlayer(scenes, outputFile, target, buildOptions); } private static string GetOutputPath() { string projectDir = Application.dataPath + "/../"; string path = Path.GetFullPath(projectDir); path += OutputDir; return path; } } |
動作的には、resourcesで指定したリポジトリのmasterブランチが更新されたらjobが起動するようになっています。
ビルドしたいプロジェクト自体は別の場所でcloneしてあり、そちらを使い回すような想定にしています。
Unityのプロジェクト自体はサイズ大きくなることが多くcloneやSwitch Platformにも時間がかかると思われるためです。
そんなことない、という場合はInputを設定すればOKです。
ファイル名はbuild_unity.ymlとしておきます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
resources: - name: Unity-Project type: git source: uri: Githubのリポジトリのアドレス # https://github.com/shamaton/hoge.git branch: master jobs: - name: build-unity plan: - get: Unity-Project trigger: true - task: let_us_build config: platform: darwin run: path: sh args: - -c - | cd path/to/project git pull /Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -quit -projectPath . -executeMethod BatchBuild.BuildiOS -logFile /dev/stdout cd ./Builds/XcodeProject xcodebuild -configuration Release archive |
1 |
fly -t sample login -c http://localhost:8080/ fly -t sample set-pipeline -p build_unity -c build_unity.yml |


もしどこかで失敗してしまう場合はビルドしているコマンドをローカルで実行してみてください。


以上です。
■ 参考 コンテナ側を使ったテストもやってみたのでyamlを載せておきます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
resources: - name: msgpack type: git icon: github-circle source: uri: https://github.com/shamaton/msgpack.git - name: golang-1.12.x-image type: registry-image icon: docker source: repository: golang tag: 1.12-stretch task-config: &task-config platform: linux inputs: - name: msgpack path: /go/src/github.com/shamaton/msgpack run: path: /bin/sh args: - -c - | SRCPATH=$PWD/go/src/github.com/shamaton/msgpack GOPATH=$PWD/go cd $SRCPATH go get -t -v ./... go test -v ./... jobs: - name: golang-1.12 public: true plan: - get: msgpack trigger: true - get: golang-1.12.x-image trigger: true - task: run-tests image: golang-1.12.x-image config: << : *task-config |