自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

用Jenkins自動化構(gòu)建Android和iOS應(yīng)用

移動開發(fā) Android iOS 自動化
使用持續(xù)集成(CI)系統(tǒng)jenkins,自動檢測并拉取最新代碼,自動打包android的apk和ios的ipa,自動上傳到內(nèi)測分發(fā)平臺蒲公英上。

背景

隨著業(yè)務(wù)需求的演進,工程的復(fù)雜度會逐漸增加,自動化的踐行日益強烈。事實上,工程的自動化一直是我們努力的目標(biāo),能有效提高我們的生產(chǎn)效率,***化減少人為出錯的概率,實現(xiàn)一些復(fù)雜的業(yè)務(wù)需求應(yīng)變。

場景如下,公司現(xiàn)在的測試人員每次需要測試新版本,都需要開發(fā)人員打包,放到ftp,測試人員然后從ftp上拷貝到本地(或者用手機的ES文件管理器),再安裝。尤其臨近發(fā)版的一周,幾乎每天都要新版本。這樣的話,有兩方面的影響:***,打斷了開發(fā)人員的開發(fā)進度;第二,開發(fā)人員打包效率低下,尤其是ios,不順的話,總是打的不對(可能是證書的問題)。

要解決這個問題,必須實現(xiàn)移動端應(yīng)用的自動化構(gòu)建。具體說來就是,使用持續(xù)集成(CI)系統(tǒng)jenkins,自動檢測并拉取***代碼,自動打包android的apk和ios的ipa,自動上傳到內(nèi)測分發(fā)平臺蒲公英上。(接下來,測試人員只要打開一個(或多個)固定的網(wǎng)址,掃描一下二維碼,就能下載***的版本了…)

環(huán)境

因為要編譯ios,所以選擇Mac OSX 10.11.1。

無論是哪個操作系統(tǒng),jenkins的配置是一樣的。

安裝Jenkins

官網(wǎng)地址:http://jenkins-ci.org/

  1. // 使用brew安裝 
  2. brew install jenkins 
  3. // 啟動,直接運行jenkins即可啟動服務(wù) 
  4. jenkins 

 

默認訪問http://localhost:8080/, 可進入jenkins配置頁面。

安裝Jenkins相關(guān)插件

點擊系統(tǒng)管理>管理插件>可選插件,可搜索以下插件安裝

  • git插件(GIT plugin)
  • ssh插件(SSH Credentials Plugin)
  • Gradle插件(Gradle plugin) – android專用
  • Xcode插件(Xcode integration) – ios專用

新建Job

主頁面,新建 -> 構(gòu)建一個自由風(fēng)格的軟件項目即可。

對于類似的項目,可以選擇 -> 復(fù)制已有的Item,要復(fù)制的任務(wù)名稱里輸入其他job的首字符會有智能提示。

配置git倉庫

如果安裝了git插件,在源碼管理會出現(xiàn)Git,選中之后:

Repositories -> https://github.com/openproject/ganchai, 如果是ssh還要配置Credentials。

Branch -> */master,選定一個要編譯的分支代碼。

如下: 

[[180854]]

 

如果是私有的倉庫(比如git://xxxxx.git),點擊Credentials – Add,彈出對話框,配置sshkey最簡單了:

 

配置自動拉取***代碼

在構(gòu)建觸發(fā)器中,有兩種自動拉取代碼并編譯的策略:

1. 設(shè)置Poll SCM,設(shè)置定時器,定時檢查代碼更新,有更新則編譯,否則不編譯(我暫時用的是這個)。   

 

2.也可以設(shè)置Build periodically,周期性的執(zhí)行編譯任務(wù)。   

 

關(guān)于定時器的格式,我只能從網(wǎng)上摘抄一段稍微靠譜一點的說明:

This field follows the syntax of cron (with minor differences). Specifically, each line consists of 5 fields separated by TABor whitespace:
 
MINUTE HOUR DOM MONTH DOW
 
MINUTE Minutes within the hour (0-59)
HOUR The hour of the day (0-23)
DOM The day of the month (1-31)
MONTH The month (1-12)
DOW The day of the week (0-7) where 0 and 7 are Sunday.
 
To specify multiple values for one field, the following operators are available. In the order of precedence,
 
   * '*' can be used to specify all valid values.
   * 'M-N' can be used to specify a range, such as "1-5"
   * 'M-N/X' or '*/X' can be used to specify skips of X''s value through the range, such as "*/15" in the MINUTE field for"0,15,30,45" and "1-6/2" for "1,3,5"
   * 'A,B,...,Z' can be used to specify multiple values, such as "0,30" or "1,3,5"
 
Empty lines and lines that start with '#' will be ignored as comments.
In addition, @yearly, @annually, @monthly, @weekly, @daily, @midnight, @hourly are supported.

 

舉兩個例子:

  1. // every minute 
  2. * * * * * 
  3. // every 5 mins past the hour 
  4. 5 * * * *  

 

配置gradle – android專用

請ios的朋友們請飄過.

如果安裝gradle插件成功的話,應(yīng)該會出現(xiàn)下圖的Invoke Gradle script,配置一下: 

 

 

 

${WORKSPACE}表示當(dāng)前job下的workspace目錄,主要是存放代碼。更多的環(huán)境變量請參考文末附錄。

這樣,就能自動在project下的app的build/outputs/apk下生成相應(yīng)的apk.

編譯失敗?可能要解決以下2個問題:

1.gradle沒配置環(huán)境變量。

比如我在/etc/profile中配置一下GRADLE_HOME:

  1. export GRADLE_HOME='/home/jay/.gradle/wrapper/dists/gradle-2.2.1-all/c64ydeuardnfqctvr1gm30w53/gradle-2.2.1' 
  2. export PATH=$GRADLE_HOME/bin:$PATH  

2.找不到local.properties中sdk定義。

因為一般來說local.properties不會添加到版本庫。所以需要手動copy到${WORKSPACE}下的Project目錄下(可參考自己Android Studio工程結(jié)構(gòu))。

關(guān)于local.properties的定義,這里記錄一下,做個備份:

  1. sdk.dir=xx/xx/android-sdk 

再編譯一般就會編譯成功,當(dāng)然當(dāng)那些第三方庫需要重新下載的話,編譯可能會很慢。

配置xcode – ios專用

請android的同學(xué)們飄過。

安裝Xcode插件后,可看到如下圖界面,并配置: 

 

 

 

這里有兩個地方需要注意。

  1. 簽名
  2. 需要Shared Schema文件.

上傳到蒲公英平臺

在官網(wǎng)文檔里有說明,通過linux平臺上傳app的關(guān)鍵代碼

  1. curl -F "file=@/tmp/example.ipa" -F "uKey=" -F "_api_key=" http://www.pgyer.com/apiv1/app/upload 

具體來說,

  1. # 先把${version}看成v1.0吧 
  2. curl -F "file=@/home/xxx/release/ganchai-release-${version}-0101-dev.apk" -F "uKey=231xxxxe6" -F"_api_key=0xxxx499" -F "publishRange=2" http://www.pgyer.com/apiv1/app/upload 

 這樣就完成一個app上傳到蒲公英了。

實際上,我們可能會面對更復(fù)雜的場景,比如上面的${version}, 而version定義于build.gradle如下:

  1. ext { 
  2.     compileSdkVersion = 22 
  3.     buildToolsVersion = "23.0.1" 
  4.     minSdkVersion = 10 
  5.     targetSdkVersion = 22 
  6.     versionCode = 1111 
  7.     versionName = "v1.2.0.0" 
  8.  

得想辦法讀到versionName, 然后拼出最終的文件名,這樣下次版本升級了之后也能動態(tài)的上傳app到蒲公英了。

  1. # 使用sed命令讀取,使用cut切割,最終動態(tài)讀取到versionName 
  2. version=`sed -n '21,1p' ${WORKSPACE}/xxx/build.gradle | cut -c20-27`  

這是android的apk上傳過程,相應(yīng)的,ios是上傳ipa,方法是一樣的,不再贅述。

小結(jié)

把開發(fā)人員發(fā)布版本的工作自動化之后,如此一來,方便了測試人員隨時拉取并構(gòu)建***版本,更解放了開發(fā)人員自己的發(fā)版本的工作,一個字,善!

附錄

jenkins中定義的那些環(huán)境變量:

  1. The following variables are available to shell scripts 
  2.   
  3. BUILD_NUMBER 
  4. The current build number, such as "153" 
  5. BUILD_ID 
  6. The current build id, such as "2005-08-22_23-59-59" (YYYY-MM-DD_hh-mm-ss) 
  7. BUILD_DISPLAY_NAME 
  8. The display name of the current build, which is something like "#153" by default
  9. JOB_NAME 
  10. Name of the project of this build, such as "foo" or "foo/bar". (To strip off folder paths from a Bourne shell script, try:${JOB_NAME##*/}) 
  11. BUILD_TAG 
  12. String of "jenkins-${JOB_NAME}-${BUILD_NUMBER}". Convenient to put into a resource file, a jar file, etc for easier identification. 
  13. EXECUTOR_NUMBER 
  14. The unique number that identifies the current executor (among executors of the same machine) that’s carrying out thisbuild. This is the number you see in the "build executor status"except that the number starts from 0, not 1. 
  15. NODE_NAME 
  16. Name of the slave if the build is on a slave, or "master" if run on master 
  17. NODE_LABELS 
  18. Whitespace-separated list of labels that the node is assigned. 
  19. WORKSPACE 
  20. The absolute path of the directory assigned to the build as a workspace. 
  21. JENKINS_HOME 
  22. The absolute path of the directory assigned on the master node for Jenkins to store data. 
  23. JENKINS_URL 
  24. Full URL of Jenkins, like http://server:port/jenkins/ (note: only available if Jenkins URL set in system configuration) 
  25. BUILD_URL 
  26. Full URL of this build, like http://server:port/jenkins/job/foo/15/ (Jenkins URL must be set
  27. JOB_URL 
  28. Full URL of this job, like http://server:port/jenkins/job/foo/ (Jenkins URL must be set
  29. SVN_REVISION 
  30. Subversion revision number that's currently checked out to the workspace, such as "12345" 
  31. SVN_URL 
  32. Subversion URL that's currently checked out to the workspace. 

 

責(zé)任編輯:龐桂玉 來源: 安卓開發(fā)精選
相關(guān)推薦

2021-08-17 09:00:00

架構(gòu)PythonWeb

2012-09-04 10:20:31

IBMdw

2021-07-14 13:11:02

papermillJupyterPython

2023-04-06 07:09:25

自動化部署Actions

2021-05-10 16:03:27

人工智能自動化技術(shù)

2013-09-03 09:58:51

Web前端

2013-05-16 10:58:44

Android開發(fā)自動化測試

2013-07-04 13:37:23

Java開發(fā)速度

2012-11-23 14:28:45

IBMdW

2011-06-03 17:06:09

自動化測試

2022-12-13 10:41:27

2017-12-17 21:58:18

2017-04-10 12:25:32

iOS自動化測試

2018-05-10 15:54:39

2023-09-13 11:40:12

2024-06-11 10:41:14

2021-06-30 19:48:21

前端自動化測試Vue 應(yīng)用

2014-04-16 14:15:01

QCon2014

2020-09-27 07:00:00

人工智能AI自動化

2022-04-08 09:05:53

Arch LinuxLinux
點贊
收藏

51CTO技術(shù)棧公眾號