forked from tmokmss/com.unity.multiplayer.samples.coop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
203 lines (191 loc) · 8.64 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
pipeline {
agent none
stages {
stage('build Unity project on spot') {
agent {
docker {
image 'unityci/editor:2021.3.14f1-ios-1.0'
args '-u root:root'
label 'linux'
}
}
steps {
// https://plugins.jenkins.io/jobcacher/
sh 'rm -rf Logs'
cache(maxCacheSize: 1000, caches: [arbitraryFileCache(path: './Logs', compressionMethod: 'ZIP')]) {
sh '''
# キャッシュ処理のデモ
ls Logs || true
'''
}
sh '''#!/bin/bash
set -xe
printenv
ls -la
echo "===Installing stuff for unity"
apt-get update
apt-get install -y curl unzip zip jq
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip -q -o awscliv2.zip
./aws/install
# S3にファイルを配置する例
echo 'File sharing via S3 example' > /tmp/sample.txt
aws s3 cp /tmp/sample.txt s3://${ARTIFACT_BUCKET_NAME}/s3_sample.txt
# Unity Build Serverからライセンスを取得:
mkdir -p /usr/share/unity3d/config/
echo '{
"licensingServiceBaseUrl": "'"$UNITY_BUILD_SERVER_URL"'",
"enableEntitlementLicensing": true,
"enableFloatingApi": true,
"clientConnectTimeoutSec": 5,
"clientHandshakeTimeoutSec": 10}' > /usr/share/unity3d/config/services-config.json
mkdir -p ./iOSProj
mkdir -p ./Build/iosBuild
unity-editor \
-quit \
-batchmode \
-nographics \
-executeMethod ExportTool.ExportXcodeProject \
-buildTarget iOS \
-customBuildTarget iOS \
-customBuildName iosBuild \
-customBuildPath ./Build/iosBuild \
-projectPath "./" \
-cacheServerEndpoint "accelerator.build:10080" \
-cacheServerNamespacePrefix "MyProject" \
-cacheServerEnableDownload true \
-cacheServerEnableUpload true \
-adb2 -enableCacheServer
echo "===Zipping Xcode project"
zip -q -r -0 iOSProj iOSProj
'''
// pick up archive xcode project
dir('') {
stash includes: 'iOSProj.zip', name: 'xcode-project'
}
}
post {
always {
// Unity Build Server利用時は明示的なライセンス返却処理は不要
// sh 'unity-editor -quit -returnlicense'
sh 'chmod -R 777 .'
}
}
}
stage('build and sign iOS app on mac') {
// we don't need the source code for this stage
options {
skipDefaultCheckout()
}
agent {
label 'mac'
}
environment {
PROJECT_FOLDER = 'iOSProj'
CERT_PRIVATE = credentials('priv')
CERT_SIGNATURE = credentials('development')
BUILD_SECRET_JSON = credentials('ios-build-secret')
}
steps {
unstash 'xcode-project'
sh '''
set -xe
printenv
ls -l
# Remove old project and unpack a new one
sudo rm -rf ${PROJECT_FOLDER}
unzip -q iOSProj.zip
'''
// create export options file
writeFile file: "${env.PROJECT_FOLDER}/ExportOptions.plist", text: """
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>signingStyle</key>
<string>manual</string>
</dict>
</plist>
"""
sh '''
# set -xe
source ~/.zshrc
# 必要なパスを通す
export PATH=/usr/local/bin:/opt/homebrew/bin:\${PATH}
# S3からファイルを取得する例
aws s3 cp s3://${ARTIFACT_BUCKET_NAME}/s3_sample.txt /tmp/s3_sample.txt
echo /tmp/s3_sample.txt
cd ${PROJECT_FOLDER}
TEAM_ID=$(echo $BUILD_SECRET_JSON | jq -r '.TEAM_ID')
BUNDLE_ID=$(echo $BUILD_SECRET_JSON | jq -r '.BUNDLE_ID')
# extra backslash for groovy
sed -i "" "s/DEVELOPMENT_TEAM = \\"\\"/DEVELOPMENT_TEAM = $TEAM_ID/g" Unity-iPhone.xcodeproj/project.pbxproj
#############################################
# setup certificates in a temporary keychain
#############################################
echo "===Setting up a temporary keychain"
pwd
# Unique keychain ID
MY_KEYCHAIN="temp.keychain.`uuidgen`"
MY_KEYCHAIN_PASSWORD="secret"
security create-keychain -p "$MY_KEYCHAIN_PASSWORD" "$MY_KEYCHAIN"
# Append the temporary keychain to the user search list
# double backslash for groovy
security list-keychains -d user -s "$MY_KEYCHAIN" $(security list-keychains -d user | sed s/\\"//g)
# Output user keychain search list for debug
security list-keychains -d user
# Disable lock timeout (set to "no timeout")
security set-keychain-settings "$MY_KEYCHAIN"
# Unlock keychain
security unlock-keychain -p "$MY_KEYCHAIN_PASSWORD" "$MY_KEYCHAIN"
echo "===Importing certs"
# Import certs to a keychain; bash process substitution doesn't work with security for some reason
security -v import $CERT_SIGNATURE -k "$MY_KEYCHAIN" -T "/usr/bin/codesign"
#rm /tmp/cert
PASSPHRASE=""
security -v import $CERT_PRIVATE -k "$MY_KEYCHAIN" -P "$PASSPHRASE" -t priv -T "/usr/bin/codesign"
# Dump keychain for debug
security dump-keychain "$MY_KEYCHAIN"
# Set partition list (ACL) for a key
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $MY_KEYCHAIN_PASSWORD $MY_KEYCHAIN
# Get signing identity for xcodebuild command
security find-identity -v -p codesigning $MY_KEYCHAIN
# double backslash for groovy
CODE_SIGN_IDENTITY=`security find-identity -v -p codesigning $MY_KEYCHAIN | awk '/ *1\\)/ {print $2}'`
echo code signing identity is $CODE_SIGN_IDENTITY
security default-keychain -s $MY_KEYCHAIN
echo $MY_MY_KEYCHAIN > keychain.txt
#############################################
# Build
#############################################
echo ===Building
pwd
xcodebuild -scheme Unity-iPhone -sdk iphoneos -configuration AppStoreDistribution archive -archivePath "$PWD/build/Unity-iPhone.xcarchive" CODE_SIGN_STYLE="Manual" CODE_SIGN_IDENTITY=$CODE_SIGN_IDENTITY OTHER_CODE_SIGN_FLAGS="--keychain=$MY_KEYCHAIN" -UseModernBuildSystem=0 CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO
zip -r build/Unity-iPhone.zip build/Unity-iPhone.xcarchive
'''
}
post {
always {
sh '''
#############################################
# cleanup
#############################################
if [ -f "keychain.txt" ]; then
security delete-keychain $(cat keychain.txt)
rm keychain.txt
fi
'''
archiveArtifacts artifacts: 'iOSProj/build/Unity-iPhone.zip', onlyIfSuccessful: true, caseSensitive: false
}
}
}
}
post {
success {
echo 'Success ^_^'
}
failure {
echo 'Failed :('
}
}
}