【Jenkins】ipaを自動生成する②(mac/Jenkins/Unity/GitHub/DeployGate)
概要
Jenkinsビルド→ipa作成までを自動で行えるようにする
今回は、Jenkinsビルド→Unityビルド(Xcode生成)まで
Jenkinsのセットアップは前回の記事
peachtea-tom.hatenablog.com
を参照
環境
Unity2019.3.13f1
Xcode 11.4.1
手順概要
Unityビルド処理の作成
public class BuildROM { // ビルド対象とするシーン static readonly string[] BUILD_SCENES = { "./Assets/main.unity" }; // 出力先 static readonly string PRODUCT_PATH = "Product"; // プロビジョニングファイルUUID static readonly string PROVISIONING_PROFILE_ADHOC = "11111111-2222-3333-4444-55555555555"; static readonly string PROVISIONING_PROFILE_APPSTORE = "6666666-7777-8888-9999-0000000000"; public static void BatchBuild(){ #if UNITY_IOS if( is_app_store_build ) { PlayerSettings.iOS.iOSManualProvisioningProfileID = PROVISIONING_PROFILE_APPSTORE; } else { PlayerSettings.iOS.iOSManualProvisioningProfileID = PROVISIONING_PROFILE_ADHOC; } #endif // ビルド var report = BuildPipeline.BuildPlayer( BUILD_SCENES, PRODUCT_PATH, BuildTarget.iOS, BuildOptions.None ); if( report.summary.result == UnityEditor.Build.Reporting.BuildResult.Succeeded ){ Debug.Log("[BUILD SUCCESS]"); }else{ Debug.LogError("[BUILD FAILED]" + report.summary ); } } }
BUILD_SCENES
PROVISIONING_PROFILE_ADHOC
PROVISIONING_PROFILE_APPSTORE
これらは適宜自分のプロジェクトに合わせて変更してください。
プロビジョニングのUDIDは
hogehoge.mobileprovision
をサクラエディタなりで開き、UUIDのkeyに設定されている文字列を指定します。
Unity PlayerSettingsの設定
Bundle Identifier:アプリのユニークなIDを設定(任意です)
Signing Team ID:プロビジョニングファイルに記載されているTeamIDを入力します。
Automatically Sign:チェックを外します。
シェルスクリプトからUnityビルド処理を実行
下記のシェルスクリプトをプロジェクトフォルダ内に入れておく。
今回はProjectフォルダのAssetsと同階層にBuildSettingsというフォルダを作成し
その中に、build.sh(下記シェルを記載したファイル)を作成
UNITY_APP_PATH="/Applications/Unity/Hub/Editor/2019.3.13f1/Unity.app/Contents/MacOS/Unity" PROJECT_PATH=$WORKSPACE UNITY_EDITOR_LOG_PATH=$WORKSPACE/build.log $UNITY_APP_PATH -batchmode -username ここにユーザ名 -password ここにパスワード -quit -logFile $UNITY_EDITOR_LOG_PATH -projectPath $PROJECT_PATH -executeMethod BuildROM.BatchBuild cat $UNITY_EDITOR_LOG_PATH