什么是 Jenkins
Jenkins是一個(gè)持續(xù)集成工具宽菜,它可以在設(shè)定的某個(gè)時(shí)間點(diǎn)(或者代碼有更新等情況)自動(dòng)去構(gòu)建安裝包愉老,同時(shí)可以將安裝包上傳到第三方平臺(tái)密任,比如:Bugly刁岸、蒲公英独郎,這樣測(cè)試人員可以通過微信液南、QQ掃一掃直接安裝(Bugly的鏈接可以直接在微信內(nèi)打開壳猜,這是我選擇它的原因)。
附上下載地址 :Jenkins
建議下載 <code>.war</code>文件 配合<code>Tomcat</code>環(huán)境使用.
直接下載了<code>.war</code>文件滑凉,這個(gè)文件是直接放在<code>Tomcat</code>下<code>webapps</code>目錄下.
優(yōu)點(diǎn):它的權(quán)限就是當(dāng)前用戶.
開始安裝Tomcat
附上下載地址 :Tomcat
把下載好的<code> Tomcat </code>文件夾 放到你想放的目錄
然后把 <code>.war</code> 文件放入 <code>Tomcat</code>文件夾下的 <code>webapps</code> 目錄下
運(yùn)行Jenkins
命令行進(jìn)入<code>Tomcat</code>安裝目錄.
<pre>
cd /Users/ooops/apache-tomcat-7.0.75/bin
</pre>
可能會(huì)報(bào) <code>-bash: /Users/ooops/apache-tomcat-7.0.75/bin/startup.sh: Permission denied</code>錯(cuò)誤,這是因?yàn)閷?duì)該文件沒有執(zhí)行權(quán)限造成的.
執(zhí)行如下命令:
<pre>
chmod +x *.sh
</pre>
然后執(zhí)行
<pre>
sh startup.sh
</pre>
打開瀏覽器輸入 localhost:8080 看到 <code>Tomcat</code>啟動(dòng)頁面,表示<code>Tomcat</code>安裝成功
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/Tomcat%E5%88%9D%E5%A7%8B%E7%95%8C%E9%9D%A2.png?raw=true)
<code>盜來的圖</code>
進(jìn)入<code>Tomcat</code>目錄下 <code>conf</code>打開 <code>tomcat-users.xml</code>文件,在文件根節(jié)點(diǎn)結(jié)束之前添加如下配置.
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/Tomcat%E7%94%A8%E6%88%B7%E7%9A%84%E9%85%8D%E7%BD%AE.png?raw=true)
使用如下命令重啟Tomcat
<pre>
cd /Users/ooops/apache-tomcat-7.0.75/bin
sh shutdown.sh
sh startup.sh
</pre>
再次登錄<code>Tomcat</code>,選擇下圖<code>Jenkins</code>
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E9%80%89%E6%8B%A9Jenkins.png?raw=true)
輸入如下命令查看Jenkins初始密碼
<pre>
open /Users/ooops/.jenkins/secrets/initialAdminPassword
</pre>
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/Jenkins%E5%88%9D%E5%A7%8B%E5%AF%86%E7%A0%81%E7%9A%84%E6%9F%A5%E7%9C%8B%E6%96%B9%E5%BC%8F.png?raw=true)
粘貼初始密碼,點(diǎn)擊繼續(xù),等待片刻
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/Jenkins%E7%99%BB%E5%BD%95%E4%B9%8B%E5%90%8E%E7%9A%84%E7%95%8C%E9%9D%A2.png?raw=true)
選擇<code>Install suggested plugins </code>
推薦的插件安裝完畢,還有我們自己需要的插件安裝.
首先進(jìn)入插件管理器界面
![](https://raw.githubusercontent.com/urm9ril/Install-Jenkins/002d8228632bcb250421f0e218703ad7d60f0f47/%E6%8F%92%E4%BB%B6%E7%AE%A1%E7%90%86%E7%95%8C%E9%9D%A2.png)
然后在可選插件中搜索我們需要的插件,進(jìn)行安裝.
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E9%9C%80%E8%A6%81%E5%AE%89%E8%A3%85%E7%9A%84%E6%8F%92%E4%BB%B6.png?raw=true)
GIT 環(huán)境下我們需要安裝的插件有 三 個(gè).操作步驟參見上圖.
- <code>Gitlab Hook Plugin </code> 因?yàn)槲覀冇玫氖荊itLab來管理源代碼蓖谢,Jenkins本身并沒有自帶GitLab插件
- <code>Xcode</code> Xcode環(huán)境插件.
- <code>Keychains and Provisioning Profiles Management</code> 鑰匙串和證書配置.
配置GIT
私鑰文件位置 家目錄下的 <code>.ssh</code> 文件夾下
配置<code>GIT</code> 私鑰
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E9%85%8D%E7%BD%AEGIT%E7%A7%81%E9%92%A5.png?raw=true)
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/GIT%E7%A7%81%E9%92%A5%E9%85%8D%E7%BD%AE.png?raw=true)
點(diǎn)擊OK完成GIT私鑰配置.
鑰匙串和證書配置
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E9%80%89%E6%8B%A9%E9%92%A5%E5%8C%99%E4%B8%B2%E5%92%8C%E8%AF%81%E4%B9%A6%E9%85%8D%E7%BD%AE.png?raw=true)
鑰匙串文件路徑 : <code> /Users/用戶名(your user name)/Library/Keychains/login.keychain</code>
上傳<code>鑰匙串 keychain </code>和 <code>證書描述文件 Provisioning Profile</code>
上傳之后的要是串和證書描述文件會(huì)被<code>Jenkins</code>保存在<code>/Users/改成你的(your user name)/.jenkins/kpp_upload</code>目錄下
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/keychain%E5%92%8C%E8%AF%81%E4%B9%A6%E6%8F%8F%E8%BF%B0%E6%96%87%E4%BB%B6%E8%AE%BE%E7%BD%AE.png?raw=true)
配置對(duì)應(yīng)的鑰匙串中的<code>開發(fā)(調(diào)試)</code> <code>生產(chǎn)(發(fā)布)</code> 證書
首先打開鑰匙串,進(jìn)行如下操作.
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E5%85%B3%E4%BA%8E%E8%AF%81%E4%B9%A6%E7%9A%84%E9%85%8D%E7%BD%AE%E9%97%AE%E9%A2%98.png?raw=true)
其次 獲取證書的常用名稱
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E8%8E%B7%E5%8F%96%E8%AF%81%E4%B9%A6%E7%9A%84%E5%B8%B8%E7%94%A8%E5%90%8D%E7%A7%B0.png?raw=true)
我們將證書的常用名稱點(diǎn)入 鑰匙串的配置中,具體配置參考下圖
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E5%AE%8C%E6%95%B4%E7%9A%84%E8%AF%81%E4%B9%A6%E5%92%8C%E8%A6%81%E6%98%AF%E4%B8%B2%E9%85%8D%E7%BD%AE.png?raw=true)
上圖目錄配置有問題,改為/Users/改成你的(your user name)/.jenkins/kpp_upload.偷個(gè)懶 不補(bǔ)圖了.
點(diǎn)擊確定完成配置.
系統(tǒng)全局配置
Jenkins 主頁 -> 系統(tǒng)管理 -> 系統(tǒng)設(shè)置 -> 全局屬性 -> 勾選<code>Keychains and Provisioning Profiles Management</code> 填入上傳到 Jenkins 的證書和描述文件目錄
<code>/Users/ooops/.jenkins/kpp_upload</code>
下面開始構(gòu)建通用項(xiàng)目配置.
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E9%80%9A%E7%94%A8%E9%A1%B9%E7%9B%AE%E9%85%8D%E7%BD%AE.png?raw=true)
參數(shù)可根據(jù)自己的實(shí)際需求更改
點(diǎn)擊確定
General 參數(shù)
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/GIT%E7%A7%81%E9%92%A5%E9%85%8D%E7%BD%AE.png?raw=true)
源碼管理 參數(shù)
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E6%BA%90%E7%A0%81%E7%AE%A1%E7%90%86.png?raw=true)
構(gòu)建觸發(fā)器設(shè)置
這里是設(shè)置自動(dòng)化測(cè)試的地方。
涉及的內(nèi)容很多譬涡,
暫時(shí)我也沒有深入研究闪幽,這里暫時(shí)先不設(shè)置。
有自動(dòng)化測(cè)試需求的可以 研究研究這里的設(shè)置涡匀。
不過這里兩個(gè)配置還是需要是設(shè)置的
<code>Poll SCM (poll source code management)</code> 輪詢?cè)创a管理
需要設(shè)置源碼的路徑才能起到輪詢的效果盯腌。
一般設(shè)置為類似結(jié)果: 0/5 每5分鐘輪詢一次
<code>Build periodically</code> (定時(shí)構(gòu)建)
一般設(shè)置為類似: 00 20 * 每天 20點(diǎn)執(zhí)行定時(shí)構(gòu)建
格式如下 (具體可以參考后面的小問號(hào)??) 嘿嘿
分鐘(0-59) 小時(shí)(0-23) 日期(1-31) 月(1-12) 周幾(0-7,0和7都是周日)
設(shè)置之后文本輸入域下面會(huì)有你填寫格式的翻譯.
參數(shù)配置參考:
http://blog.csdn.net/xueyingqi/article/details/53216506
http://blog.csdn.net/yezicjj/article/details/52763700
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E6%9E%84%E5%BB%BA%E8%A7%A6%E5%8F%91%E5%99%A8.png?raw=true)
構(gòu)建環(huán)境 參數(shù)
參考下圖設(shè)置
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E6%9E%84%E5%BB%BA%E7%8E%AF%E5%A2%83%E8%AF%81%E4%B9%A6%E5%92%8C%E8%A6%81%E9%92%A5%E5%8C%99%E4%B8%B2%E7%9A%84%E9%80%89%E6%8B%A9%E9%97%AE%E9%A2%98.png?raw=true)
如果這里沒有可選擇的鑰匙串和描述文件,請(qǐng)參考 鑰匙串和證書配置 中關(guān)于鑰匙串的配置.
構(gòu)建 設(shè)置
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E6%9E%84%E5%BB%BA%E7%9A%84%E8%84%9A%E6%9C%AC%E8%AE%BE%E7%BD%AE.png?raw=true)
<pre>
工程名
APP_NAME="你的項(xiàng)目名稱"
證書
CODE_SIGN_DISTRIBUTION="iPhone Developer: XXXXXXX"
CODE_SIGN_DISTRIBUTION="iPhone Distribution: XXXXXXXXXX"
info.plist路徑
project_infoplist_path="./${APP_NAME}/Info.plist"
取版本號(hào)
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${project_infoplist_path}")
取build值
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${project_infoplist_path}")
DATE="$(date +%Y%m%d)"
IPANAME="${APP_NAME}V${bundleShortVersion}${DATE}.ipa"
IPANAME="${APP_NAME}.ipa"
要上傳的ipa文件路徑
IPA_PATH="$HOME/${IPANAME}"
echo ${IPA_PATH}
echo "${IPA_PATH}">> text.txt
下面2行是沒有Cocopods的用法
echo "=================clean================="
xcodebuild -target "${APP_NAME}" -configuration 'Release' clean
echo "+++++++++++++++++build+++++++++++++++++"
xcodebuild -target "${APP_NAME}" -sdk iphoneos -configuration 'Release' CODE_SIGN_IDENTITY="${CODE_SIGN_DISTRIBUTION}" SYMROOT='$(PWD)'
//下面2行是集成有Cocopods的用法
echo "=================clean================="
xcodebuild -workspace "${APP_NAME}.xcworkspace" -scheme "${APP_NAME}" -configuration 'Release' clean
echo "+++++++++++++++++build+++++++++++++++++"
xcodebuild -workspace "${APP_NAME}.xcworkspace" -scheme "${APP_NAME}" -sdk iphoneos -configuration 'Release' CODE_SIGN_IDENTITY="${CODE_SIGN_DISTRIBUTION}" SYMROOT='$(PWD)'
xcrun -sdk iphoneos PackageApplication "./Release-iphoneos/${APP_NAME}.app" -o ~/"${IPANAME}"
蒲公英上的User Key
uKey="9b0aa78a32a......4e1ca68bdbf"
蒲公英上的API Key
apiKey="ac75fcf38.....7b9f19f2e4b23"
要上傳的ipa文件路徑
IPA_PATH=$(cat text.txt)
rm -rf text.txt
執(zhí)行上傳至蒲公英的命令
echo "++++++++++++++upload+++++++++++++"
curl -F "file=@${IPA_PATH}" -F "uKey=${uKey}" -F "_api_key=${apiKey}" http://www.pgyer.com/apiv1/app/upload
</pre>
構(gòu)建項(xiàng)目
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E6%9E%84%E5%BB%BA%E9%A1%B9%E7%9B%AE%E5%9B%BE.png?raw=true)
以下是一次成功構(gòu)建的輸出信息
<pre>
Started by user ooops
Building in workspace /Users/ooops/.jenkins/workspace/test
git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository //拉取GIT倉庫
git config remote.origin.url git@github.com:xxxxx/jenkinsTest.git # timeout=10
Fetching upstream changes from git@github.com:xxxxx/jenkinsTest.git
git --version # timeout=10
git fetch --tags --progress git@github.com:xxxxx/jenkinsTest.git +refs/heads/:refs/remotes/origin/
git rev-parse refs/remotes/origin/master^{commit} # timeout=10
git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 1f023f0132273ddc4d3d98a8283e3a15bbe254aa (refs/remotes/origin/master)
git config core.sparsecheckout # timeout=10
git checkout -f 1f023f0132273ddc4d3d98a8283e3a15bbe254aa
git rev-list 1f023f0132273ddc4d3d98a8283e3a15bbe254aa # timeout=10
[test] $ /bin/sh -xe /Users/ooops/apache-tomcat-7.0.75/temp/hudson6997647762219224773.sh
- APP_NAME=jenkinsTest
- CODE_SIGN_DISTRIBUTION='iPhone Developer: xxxxx'
- project_infoplist_path=./jenkinsTest/Info.plist
++ /usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' ./jenkinsTest/Info.plist - bundleShortVersion=1.0
++ /usr/libexec/PlistBuddy -c 'print CFBundleVersion' ./jenkinsTest/Info.plist - bundleVersion=1
++ date +%Y%m%d - DATE=20170312
- IPANAME=jenkinsTest_V1.0_20170312.ipa
- IPA_PATH=/Users/ooops/jenkinsTest_V1.0_20170312.ipa
- echo /Users/ooops/jenkinsTest_V1.0_20170312.ipa
/Users/ooops/jenkinsTest_V1.0_20170312.ipa - echo /Users/ooops/jenkinsTest_V1.0_20170312.ipa
- echo =================clean=================
=================clean================= - xcodebuild -target jenkinsTest -configuration Release clean
2017-03-12 12:56:15.278 xcodebuild[12363:1935879] [MT] PluginLoading: Required plug-in compatibility UUID DAxxxD8-C509-4xB-8xx5-84xxxxxxx701 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2017-03-12 12:56:15.279 xcodebuild[12363:1935879] [MT] PluginLoading: Required plug-in compatibility UUID DAxxxD8-C509-4xB-8xx5-84xxxxxxx701 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/HOStringSense.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2017-03-12 12:56:15.280 xcodebuild[12363:1935879] [MT] PluginLoading: Required plug-in compatibility UUID DAxxxD8-C509-4xB-8xx5-84xxxxxxx701 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ESJsonFormat.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2017-03-12 12:56:15.280 xcodebuild[12363:1935879] [MT] PluginLoading: Required plug-in compatibility UUID DAxxxD8-C509-4xB-8xx5-84xxxxxxx701 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Auto-Importer.xcplugin' not present in DVTPlugInCompatibilityUUIDs
=== CLEAN TARGET jenkinsTest OF PROJECT jenkinsTest WITH CONFIGURATION Release ===
Check dependencies
Create product structure
/bin/mkdir -p /Users/ooops/.jenkins/workspace/test/build/Release-iphoneos/jenkinsTest.app
Clean.Remove clean build/jenkinsTest.build/Release-iphoneos/jenkinsTest.build
builtin-rm -rf /Users/ooops/.jenkins/workspace/test/build/jenkinsTest.build/Release-iphoneos/jenkinsTest.build
Clean.Remove clean build/Release-iphoneos/jenkinsTest.app
builtin-rm -rf /Users/ooops/.jenkins/workspace/test/build/Release-iphoneos/jenkinsTest.app
Clean.Remove clean build/Release-iphoneos/jenkinsTest.app.dSYM
builtin-rm -rf /Users/ooops/.jenkins/workspace/test/build/Release-iphoneos/jenkinsTest.app.dSYM
** CLEAN SUCCEEDED **
- echo +++++++++++++++++build+++++++++++++++++
+++++++++++++++++build+++++++++++++++++ - xcodebuild -target jenkinsTest -sdk iphoneos -configuration Release 'CODE_SIGN_IDENTITY=iPhone Developer: xxxxxxxxxxxxxxxx' 'SYMROOT=$(PWD)'
2017-03-12 12:56:16.118 xcodebuild[12376:1936105] [MT] PluginLoading: Required plug-in compatibility UUID DAxxxx8-C509-4xxB-8B55-84AxxxxxE701 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2017-03-12 12:56:16.119 xcodebuild[12376:1936105] [MT] PluginLoading: Required plug-in compatibility UUID DAxxxxD8-C509-4D8B-8xxxx-84Axxxx01 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/HOStringSense.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2017-03-12 12:56:16.119 xcodebuild[12376:1936105] [MT] PluginLoading: Required plug-in compatibility UUID DA4xxx8-C509-4Dxx-8xx5-84AxxxE701 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ESJsonFormat.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2017-03-12 12:56:16.120 xcodebuild[12376:1936105] [MT] PluginLoading: Required plug-in compatibility UUID Dxxxx8-C509-xx-8B55-84xxxxxAE701 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Auto-Importer.xcplugin' not present in DVTPlugInCompatibilityUUIDs
Build settings from command line:
CODE_SIGN_IDENTITY = iPhone Developer: qiang zhang (36XGYU49EQ)
SDKROOT = iphoneos10.1
SYMROOT = $(PWD)
=== BUILD TARGET jenkinsTest OF PROJECT jenkinsTest WITH CONFIGURATION Release ===
Check dependencies
Validate Release-iphoneos/jenkinsTest.app
cd /Users/ooops/.jenkins/workspace/test
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Users/ooops/.rvm/gems/ruby-2.2.2/bin:/Users/ooops/.rvm/gems/ruby-2.2.2@global/bin:/Users/ooops/.rvm/rubies/ruby-2.2.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ooops/.rvm/bin:/Users/ooops/.rvm/bin"
export PRODUCT_TYPE=com.apple.product-type.application
builtin-validationUtility /Users/ooops/.jenkins/workspace/test/Release-iphoneos/jenkinsTest.app -validate-for-store
** BUILD SUCCEEDED **
- xcrun -sdk iphoneos PackageApplication ./Release-iphoneos/jenkinsTest.app -o /Users/ooops/jenkinsTest_V1.0_20170312.ipa
warning: PackageApplication is deprecated, use xcodebuild -exportArchive
instead.
//這里是上傳蒲公英的配置.
uKey=9b0aa78a32........64e1ca68bdbf
apiKey=ac75fcf3..........a47b9f19f2e4b23
++ cat text.txtIPA_PATH=/Users/ooops/jenkinsTest_V1.0_20170312.ipa
rm -rf text.txt
echo ++++++++++++++upload+++++++++++++
++++++++++++++upload+++++++++++++-
curl -F file=@/Users/ooops/jenkinsTest_V1.0_20170312.ipa -F uKey=9b0aa78a32...af26..4e1ca68bdbf -F _api_key=ac75fcf38f2.........19f2e4b23 http://www.pgyer.com/apiv1/app/upload
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 32843 0 0 100 32843 0 21213 0:00:01 0:00:01 --:--:-- 21202
100 32843 0 0 100 32843 0 12862 0:00:02 0:00:02 --:--:-- 12859
100 33438 100 595 100 32843 220 12149 0:00:02 0:00:02 --:--:-- 12146
{"code":0,"message":"","data":{"appKey":"dd580f5...........0305ac671","userKey":"9b0aa78a.........e1ca68bdbf","appType":"1","appIsLastest":"1","appFileSize":"32368","appName":"jenkinsTest","appVersion":"1.0","appVersionNo":"1","appBuildVersion":"2","appIdentifier":"com.ooops.pull","appIcon":"","appDescription":"","appUpdateDescription":"","appScreenshots":"","appShortcutUrl":"nZwg","appCreated":"2017-03-12 12:56:18","appUpdated":"2017-03-12 12:56:18","appQRCodeURL":"http://static.pgyer.com/app/qrcodeHistory/ea895709d0e57a4a8e4c8f57811838b2ce985322a94f9443e64a0937c6d29e30"}}Finished: SUCCESS
</pre>
上傳到蒲公英
![](https://github.com/urm9ril/Install-Jenkins/blob/Jenkins/%E8%92%B2%E5%85%AC%E8%8B%B1.png?raw=true)