Jenkins一鍵發(fā)布 ipa 到蒲公英

什么是 Jenkins

Jenkins是一個持續(xù)集成工具,它可以在設定的某個時間點(或者代碼有更新等情況)自動去構建安裝包,同時可以將安裝包上傳到第三方平臺,比如:Bugly、蒲公英,這樣測試人員可以通過微信、QQ掃一掃直接安裝(Bugly的鏈接可以直接在微信內(nèi)打開,這是我選擇它的原因)。

附上下載地址 :Jenkins

建議下載 <code>.war</code>文件 配合<code>Tomcat</code>環(huán)境使用.

直接下載了<code>.war</code>文件,這個文件是直接放在<code>Tomcat</code>下<code>webapps</code>目錄下.

優(yōu)點:它的權限就是當前用戶.

開始安裝Tomcat

附上下載地址 :Tomcat

把下載好的<code> Tomcat </code>文件夾 放到你想放的目錄

然后把 <code>.war</code> 文件放入 <code>Tomcat</code>文件夾下的 <code>webapps</code> 目錄下

運行Jenkins

命令行進入<code>Tomcat</code>安裝目錄.

<pre>
cd /Users/ooops/apache-tomcat-7.0.75/bin
</pre>
可能會報 <code>-bash: /Users/ooops/apache-tomcat-7.0.75/bin/startup.sh: Permission denied</code>錯誤,這是因為對該文件沒有執(zhí)行權限造成的.

執(zhí)行如下命令:
<pre>
chmod +x *.sh
</pre>
然后執(zhí)行
<pre>
sh startup.sh
</pre>
打開瀏覽器輸入 localhost:8080 看到 <code>Tomcat</code>啟動頁面,表示<code>Tomcat</code>安裝成功


<code>盜來的圖</code>

進入<code>Tomcat</code>目錄下 <code>conf</code>打開 <code>tomcat-users.xml</code>文件,在文件根節(jié)點結束之前添加如下配置.


使用如下命令重啟Tomcat
<pre>
cd /Users/ooops/apache-tomcat-7.0.75/bin
sh shutdown.sh
sh startup.sh
</pre>
再次登錄<code>Tomcat</code>,選擇下圖<code>Jenkins</code>


輸入如下命令查看Jenkins初始密碼
<pre>
open /Users/ooops/.jenkins/secrets/initialAdminPassword
</pre>



粘貼初始密碼,點擊繼續(xù),等待片刻


選擇<code>Install suggested plugins </code>

推薦的插件安裝完畢,還有我們自己需要的插件安裝.
首先進入插件管理器界面


然后在可選插件中搜索我們需要的插件,進行安裝.


GIT 環(huán)境下我們需要安裝的插件有 三 個.操作步驟參見上圖.

  • <code>Gitlab Hook Plugin </code> 因為我們用的是GitLab來管理源代碼,Jenkins本身并沒有自帶GitLab插件
  • <code>Xcode</code> Xcode環(huán)境插件.
  • <code>Keychains and Provisioning Profiles Management</code> 鑰匙串和證書配置.

配置GIT

私鑰文件位置 家目錄下的 <code>.ssh</code> 文件夾下

配置<code>GIT</code> 私鑰




點擊OK完成GIT私鑰配置.

鑰匙串和證書配置

鑰匙串文件路徑 : <code> /Users/用戶名(your user name)/Library/Keychains/login.keychain</code>

上傳<code>鑰匙串 keychain </code>和 <code>證書描述文件 Provisioning Profile</code>
上傳之后的要是串和證書描述文件會被<code>Jenkins</code>保存在<code>/Users/改成你的(your user name)/.jenkins/kpp_upload</code>目錄下

配置對應的鑰匙串中的<code>開發(fā)(調(diào)試)</code> <code>生產(chǎn)(發(fā)布)</code> 證書

首先打開鑰匙串,進行如下操作.

其次 獲取證書的常用名稱


我們將證書的常用名稱點入 鑰匙串的配置中,具體配置參考下圖

上圖目錄配置有問題,改為/Users/改成你的(your user name)/.jenkins/kpp_upload.偷個懶 不補圖了.

點擊確定完成配置.

系統(tǒng)全局配置

Jenkins 主頁 -> 系統(tǒng)管理 -> 系統(tǒng)設置 -> 全局屬性 -> 勾選<code>Keychains and Provisioning Profiles Management</code> 填入上傳到 Jenkins 的證書和描述文件目錄
<code>/Users/ooops/.jenkins/kpp_upload</code>

下面開始構建通用項目配置.

參數(shù)可根據(jù)自己的實際需求更改

點擊確定

General 參數(shù)

源碼管理 參數(shù)

構建觸發(fā)器設置

這里是設置自動化測試的地方。
涉及的內(nèi)容很多,
暫時我也沒有深入研究,這里暫時先不設置。
有自動化測試需求的可以 研究研究這里的設置。

不過這里兩個配置還是需要是設置的

<code>Poll SCM (poll source code management)</code> 輪詢源碼管理

需要設置源碼的路徑才能起到輪詢的效果。

一般設置為類似結果: 0/5 每5分鐘輪詢一次

<code>Build periodically</code> (定時構建)

一般設置為類似: 00 20 * 每天 20點執(zhí)行定時構建

格式如下 (具體可以參考后面的小問號??) 嘿嘿

分鐘(0-59) 小時(0-23) 日期(1-31) 月(1-12) 周幾(0-7,0和7都是周日)

設置之后文本輸入域下面會有你填寫格式的翻譯.

參數(shù)配置參考:

http://blog.csdn.net/xueyingqi/article/details/53216506

http://blog.csdn.net/yezicjj/article/details/52763700

構建環(huán)境 參數(shù)

參考下圖設置

如果這里沒有可選擇的鑰匙串和描述文件,請參考 鑰匙串和證書配置 中關于鑰匙串的配置.

構建 設置

<pre>

工程名

APP_NAME="你的項目名稱"

證書

CODE_SIGN_DISTRIBUTION="iPhone Developer: XXXXXXX"

CODE_SIGN_DISTRIBUTION="iPhone Distribution: XXXXXXXXXX"

info.plist路徑

project_infoplist_path="./${APP_NAME}/Info.plist"

取版本號

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>

構建項目

以下是一次成功構建的輸出信息

<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.txt

  • IPA_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 Speed

    0 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>

上傳到蒲公英

END

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容