1. 程式人生 > >Jenkins+Gitlab+蒲公英構建Android專案, 實現自動打包上傳並生產二維碼下載

Jenkins+Gitlab+蒲公英構建Android專案, 實現自動打包上傳並生產二維碼下載

基本準備

# 關閉selinux

setenforce  0

sed   -i     '/=enforcing/s/enforcing/disabled/g'  /etc/sysconfig/selinux

# 關閉防火牆

service   iptables  stop  &&  chkconfig  iptables  off

注意關鍵字:Development 

需要oracle的賬號,請自行註冊

# rpm -ivh  jdk-8u172-linux-x64.rpm

# java  -version

[[email protected]

~]# unzip   gradle-3.1-all.zip

[[email protected] ~]# vim /etc/profile

GRADLE_HOME=/root/soft/gradle-3.1

PATH=${PATH}:${GRADLE_HOME}/bin

記得export

:wq

[[email protected] ~]# source /etc/profile

[[email protected] ~]# gradle -v

------------------------------------------------------------

Gradle 3.1

------------------------------------------------------------

Build time:   2016-09-19 10:53:53 UTC

Revision:     13f38ba699afd86d7cdc4ed8fd7dd3960c0b1f97

Groovy:       2.4.7

Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015

JVM:          1.8.0_172 (Oracle Corporation 25.172-b11)

OS:           Linux 2.6.32-696.el6.x86_64 amd64

[[email protected] ~]# vim   /etc/yum.repos.d/jenkins.repo     //關掉gpgcheck

[[email protected] ~]# yum install jenkins

[[email protected] ~]# vim /etc/sysconfig/Jenkins

29 JENKINS_USER="root"   //防止許可權衝突

56 JENKINS_PORT="8080"   //預設埠8080

:wq

[[email protected] ~]# vim /etc/profile

export JENKINS_HOME=/var/lib/jenkins/

:wq

[[email protected] ~]# source /etc/profile

[[email protected] ~]# echo $JENKINS_HOME

/var/lib/jenkins/

[[email protected] ~]# service jenkins start

//這時候會發現/usr/lib/jenkins/下面就有了jenkins.war檔案,無需wget從官網下載

[[email protected] ~]# cd /usr/lib/jenkins/

[[email protected] jenkins]# ll

總用量 73016

-rw-r--r--. 1 root root 74764818 8月  15 22:32 jenkins.war

[[email protected] ~]# vim /var/log/jenkins/jenkins.log

       //檢視jenkins的日誌,最後一行顯示Listed all plugins或者Jenkins is fully up and running表示jenkins服務正常執行中

選擇推薦安裝,多一個不多嘛 - -  萬一有天要用呢

分割線————————————————————————————————————————————————————————

環境:

Gitlab:192.168.1.111

Jenkins:192.168.1.112

Git伺服器稱為A、Jenkins稱為B這樣子

兩臺機器相同操作開啟RSA認證

vim /etc/ssh/sshd_config

47 RSAAuthentication yes

48 PubkeyAuthentication yes

49 AuthorizedKeysFile      .ssh/authorized_keys

:wq

service  sshd  restart

[[email protected] .ssh]# ssh-keygen               //如果之前配置好過git的可以免了

# 把公鑰新增到B伺服器的authorized_keys

A伺服器: cat  id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuyoyNHXdiUHiV/CBD7rwcLDuLTYSgp1xKvo+Zycop734gYWyUVal8b/SAlWErZ7s8JCIwmxbeLWpyPKPRm9j919Va0eitc9H4JYBbZCd60apj+odH7MRcDYfSeJjJX513SeHIMNhUe+TT+ujm6X2gPkjpe/pq+gdbj+aRme33Ym+bgxtn7uQJQNANwrm4CdRtEcakbUwIOTczgGlIk5pAXA2xMZkJ/OnkZj2RI18Dk7pZEG0DH0FuGJ9nRuOFsoyybt5btKJMlIGIfhdJ0lhrDgllJiFoTuBczFp2cU3eth25/0OR9Wu2JRIdIKLmIT1EP5RCuernbmW2HRlcMUIAQ==

B伺服器: cat  /root/.ssh/authorized_keys

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuyoyNHXdiUHiV/CBD7rwcLDuLTYSgp1xKvo+Zycop734gYWyUVal8b/SAlWErZ7s8JCIwmxbeLWpyPKPRm9j919Va0eitc9H4JYBbZCd60apj+odH7MRcDYfSeJjJX513SeHIMNhUe+TT+ujm6X2gPkjpe/pq+gdbj+aRme33Ym+bgxtn7uQJQNANwrm4CdRtEcakbUwIOTczgGlIk5pAXA2xMZkJ/OnkZj2RI18Dk7pZEG0DH0FuGJ9nRuOFsoyybt5btKJMlIGIfhdJ0lhrDgllJiFoTuBczFp2cU3eth25/0OR9Wu2JRIdIKLmIT1EP5RCuernbmW2HRlcMUIAQ== [email protected]

                                                        //必須一樣!!!

A嘗試登陸B

B嘗試登陸A

專案構建

提前核對下專案配置檔案所需求的外掛:

主要檢視:buildToolsVersion,compileSdkVersion,compileOptions(Java版本)

              //每個module目錄都要自己檢視

下載Android SDK 或者 通過AS安裝SDK(需要圖形化支援)

本次專案用的是命令列方式、

[[email protected] ~]# cd  /root/soft/

[[email protected] ~]# tar -xf  android-sdk_r24.4.1-linux.tgz

[[email protected] ~]# cd  android-sdk-linux/tools/

[[email protected] ~]# ./android update sdk --no-ui        //更新SDK

[[email protected] ~]# vim  /etc/profile

ANDROID_HOME=/root/soft/android-sdk-linux

GRADLE_HOME=/root/soft/gradle-3.1

PATH=${PATH}:${GRADLE_HOME}/bin:$ANDROID_HOME/tools

export  ANDROID_HOME GRADLE_HOME PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

export JENKINS_HOME=/var/lib/jenkins/

:wq

[[email protected] ~]# source  /etc/profile

[[email protected] ~]# android list sdk  --all        //檢視可用元件

# 下載需要的元件, 注意--all 這個引數一定要加上, 否則後面filter裡的序號不起作用

例如我用的是

android update sdk -u --all -filter 1,2,6,47

       //當構建時報錯是缺少外掛的, 即可到這裡獲取(有條件update全部,去掉-filter選項)

yum install git  在再”全域性工具配置”配置下

git和svn就跳過了,直接來實用的:

報錯處理

//檢查aapt檔案是存在的,原因是centos下缺少C++的語言庫

yum install gcc gcc-c++

檢視aapt 是否工作正常

提示需要GLIBC_2.14版本

這是因為升級了glibc的原因

解決方法:

[[email protected] ~]# vim /etc/sysconfig/i18n 

LANG="zh_CN.utf8"

LC_ALL=C

export LC_ALL

:wq

[[email protected] ~]# source   /etc/sysconfig/i18n

重新登入即可

先去蒲公英官網註冊一個賬號,實名認證過後,獲取到API及user的KEY

構建 --> 執行shell中 新增

curl -F "[email protected]這裡是你的APK檔案位置" -F "uKey=蒲公英的key" -F "_api_key=蒲公英的api_KEY" https://www.pgyer.com/apiv1/app/upload