Jenkins for cordova

專案環境 cordova + angular4 hybrid app

承上次建立的jenkins環境是基於將建立之platform資料夾上版控(通常不會這麼做),所以android和iOS不會因為專案設定導致編譯不成功

限制: platform不上版控server,將iOS和Android編譯成品出來

Android問題

1
sh "./gradlew clean assembleRelease"
描述:新建立Android環境時,並沒有gradlew這指令,所以這行就會報錯。
思考:開啟Android Studio後又會自動產生gradlew檔案。
解決方法:在android資料夾中下gradle指令就會執行gradle環境建置,就會產生gradlew檔案,然後再將加執行權限。
1
2
gradle wrapper
chmod +x ./gradlew
前置作業: 將環境變數設定好,在command line中可以呼叫gradle指令,如果不能呼叫,請先加入執行權限。
1
chmod +x gradle
1
2
3
4
5
export ANDROID_HOME=/Users/devilcry/Library/Android/sdk
export GRADLE_HOME=/Applications/Android\ Studio\ 3.app/Contents/gradle/gradle-4.6
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${GRADLE_HOME}/bin:${ANDROID_HOME}

iOS問題

1
xcodebuild archive -scheme XXXX -target XXXX -archivePath ./ht_build/${BUILD_TAG}.xcarchive
描述:新建立iOS環境時,並沒有進入專案內設定singing勾選automatic manage signing,所以在編譯時,會因為找不到相對應的Provisioning Profile而編譯失敗。
思考:不使用automatic manage signing的功能,手動管理Provisioning Profile。
解決方法:先解開keychain,為啥要先解開keychain,可以找上一篇,再利用xcodebuild中的option塞進我們想要的Provisioning Profile,記得加上-UseModernBuildSystem=NO,不然預設編譯為new build system而不是legacy build system。
1
2
3
4
5
6
7
8
9
10
echo "[ Build Info ], STAGING, UnlockKeyChain"
security unlock-keychain -p yourpassword /Users/XXXX/Library/Keychains/login.keychain
echo "[ Build Info ], STAGING, Clean"
sh "xcodebuild clean -scheme tcbb-mobile-bank -configuration Release -UseModernBuildSystem=NO"

echo "[ Build Info ], STAGING, Archive"
sh "xcodebuild -scheme tcbb-mobile-bank -sdk iphoneos -archivePath ./ht_build/${BUILD_TAG}.xcarchive -configuration Release -allowProvisioningUpdates CODE_SIGN_IDENTITY='iPhone Developer: xxx (xxxxxx)' PROVISIONING_PROFILE='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' CODE_SIGN_STYLE='Manual' DEVELOPMENT_TEAM='xxxxxxxxxx' -UseModernBuildSystem=NO archive"

echo "[ Build Info ], STAGING, Export Archive"
sh "xcodebuild -exportArchive -archivePath ./ht_build/${BUILD_TAG}.xcarchive -exportOptionsPlist ./ExportOptions.plist -exportPath ./ht_build/${BUILD_TAG}"
前置作業: CODE_SIGN_IDENTITY塞keychain上面那張憑證;PROVISIONING_PROFILE透過xcode手動下載後,在/User/XXXX/Library/MobileDevice/Provisioning Profiles內相對應的編號填入這邊;DEVELOPMENT_TEAM則填入team_id,在appleDeveloper網站可以看得到自己的team_id。ExportOptions.plist一樣從xcode內手動執行一次,export出來的ipa就會有這個檔案,這邊需注意的是必須選Manually manage singing,這樣所產出的plist才會是我們需要的。