forked from yosizo/TestJenkinsScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
131 lines (101 loc) · 5.28 KB
/
Jenkinsfile
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
node {
// ビルド対象リポジトリ
def repositoryURL = 'https://[your_build_target_project_repository].git'
// ローカルリポジトリディレクトリ名
def repositoryName = "[your_repository_name]"
// Unityプロジェクト名
def projectName = "[your_project_name]"
// JenkinsワークスペースにチェックアウトされるUnityプロジェクトパス
def projectPath = "${WORKSPACE}/${repositoryName}/${projectName}"
// XcodeアーカイブPath
def archivePath = "${projectPath}/iOS/build/${projectName}.xcarchive"
// ユーザーが選択したブランチ名
def buildBranchName
stage('InputParam') {
// リモートからブランチの一覧を取得しプルダウンリスト用に整形する
def branchList = sh(script: "git ls-remote --heads ${repositoryURL} | sed -e 's#.*refs/heads/##'", returnStdout: true)
// 入力待ち状態で5分経過したらタイムアウトする
timeout(time:5,unit:"MINUTES")
{
def defaultBranch = "develop"
// デプロイセッティングの入力待ち
def inputParam = input(
message: 'ビルドパラメーターをセットしてください',
ok: 'ビルド開始',
parameters: [
[$class:"ChoiceParameterDefinition",
name: 'branchName',
choices: branchList,
defaultValue: defaultBranch,
description: 'ビルド対象のブランチを選択してください'
],
]
)
buildBranchName = inputParam.branchName
}
}
stage('Git') {
dir (repositoryName) {
// ブランチをチェックアウト
git( branch: buildBranchName, url: repositoryURL)
}
}
stage('Unity Build') {
// UnityコマンドPath
def unityPath = "/Applications/Unity/Unity.app/Contents/MacOS/Unity"
// Unityビルドスクリプトクラス名
// ※ここはUnity側に設置したバッチビルド用クラスとメソッド名を指定してください
def executeMethod = "AppBuildBatch.BuildIOSDevelop"
// ビルドターゲット
def buildTarget = "ios"
// UnityのバッチビルドでXcodeプロジェクトをビルドするためのコマンド文字列を作成
def buildCommand = "${unityPath} -quit -batchmode"
buildCommand += " -executeMethod ${executeMethod}"
buildCommand += " -projectPath ${projectPath}"
buildCommand += " -buildTarget ${buildTarget}"
// ビルドコマンドを実行
sh(script: buildCommand)
}
stage('xcode build')
{
// XcodeプロジェクトPath
def xcodeprojDir = "${projectPath}/iOS/"
def xcodeproj = "${xcodeprojDir}Unity-iPhone.xcodeproj"
// 設定項目(必要に応じて適宜設定してください)
def bundleID = "xxxxxxxxx"
def displayName = "xxxxxxxxxxxxx"
def versionNumber = "xxxxxxxxxxxxx"
def BuildNumber = "xxxxxxxxx"
// Plistbuddyで設定項目を書き換える
sh("/usr/libexec/Plistbuddy -c \"Set CFBundleIdentifier ${bundleID}\" ${xcodeprojDir}Info.plist")
sh("/usr/libexec/Plistbuddy -c \"Set CFBundleDisplayName ${displayName}\" ${xcodeprojDir}Info.plist")
sh("/usr/libexec/Plistbuddy -c \"Set CFBundleShortVersionString ${versionNumber}\" ${xcodeprojDir}Info.plist")
sh("/usr/libexec/Plistbuddy -c \"Set CFBundleVersion ${BuildNumber}\" ${xcodeprojDir}Info.plist")
// ビルド環境をクリーン
sh(script: "xcodebuild clean -project ${xcodeproj}")
// XcodeBuildコマンドでアーカイブ作成
def developmentTeamName = "xxxxxxxxxxxxxx"
def provisioningProfilerSpecifier = "xxxxxxxxxxxxxxx"
sh(script: "xcodebuild archive -project ${xcodeproj} -archivePath ${archivePath} -configuration Develop -scheme Unity-iPhone -sdk iphoneos10.3 CODE_SIGN_IDENTITY=\"iPhone Distribution\" PROVISIONING_PROFILE_SPECIFIER=${provisioningProfilerSpecifier} DEVELOPMENT_TEAM=${developmentTeamName}")
}
stage('ipa export')
{
// ipaビルド設定ファイルPath
def exportOptionFile = "${WORKSPACE}/build/buildparams/exportOptions.plist"
// ipa出力先
def exportDir = "${WORKSPACE}/export/${BUILD_NUMBER}/"
def exportFileName = "${projectName}_${BUILD_NUMBER}.ipa"
// exportディレクトリがなければ作成
dir ('export') {
// XcodeBuildコマンドでipa作成
sh(script: "xcodebuild -exportArchive -archivePath ${archivePath} -exportPath ${exportDir} -exportOptionsPlist ${exportOptionFile}")
if( fileExists("${BUILD_NUMBER}/Unity-iPhone.ipa") )
{
// そのままだと毎回、Unity-iPhone.ipaというファイルが生成されるので、アーカイブ用にリネーム
sh(script:"mv ${BUILD_NUMBER}/Unity-iPhone.ipa ${BUILD_NUMBER}/${exportFileName}")
// アーカイブ
archiveArtifacts(artifacts: "${BUILD_NUMBER}/${exportFileName}", onlyIfSuccessful: true)
}
}
}
}