🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
前提条件 配置maven和jdk省略(看之前文档) 测试代码:https://github.com/HarkBen/TestJenkins 一)安装gradle 下载地址:https://gradle.org/releases/(可以选择项目需要的) http://soft.51yuki.cn/gradle-2.14.1-all.zip [root@jenkins www]# wget http://soft.51yuki.cn/gradle-2.14.1-all.zip [root@jenkins www]# unzip gradle-2.14.1 [root@jenkins www]# ln -sv gradle-2.14.1 gradle [root@jenkins www]# echo "PATH=/home/www/gradle/bin:$PATH" >> /home/www/.bash_profile [root@jenkins www]# echo "PATH=/home/www/gradle/bin:$PATH" >> /etc/profile.d/gradle.sh [root@jenkins www]# source /home/www/.bash_profile [root@jenkins www]# source /etc/profile.d/gradle.sh 查看: [root@jenkins www]# gradle -version ------------------------------------------------------------ Gradle 4.1 ------------------------------------------------------------ Build time: 2017-08-07 14:38:48 UTC Revision: 941559e020f6c357ebb08d5c67acdb858a3defc2 Groovy: 2.4.11 Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015 JVM: 1.8.0_151 (Oracle Corporation 25.151-b12) OS: Linux 2.6.32-642.el6.x86_64 amd64 二)安装android-sdk 网站:http://tools.android-studio.org/index.php/sdk/ [root@jenkins ~]# cd /home/www [root@jenkins www]# wget http://soft.51yuki.cn/android-sdk_r24.4.1-linux.tgz [root@jenkins www]# tar xf android-sdk_r24.4.1-linux.tgz [root@jenkins www]# ln -sv android-sdk_r24.4.1/ sdk 配置环境变量 root@jenkins www]# echo "PATH=/home/www/sdk/tools/:$PATH" >> /home/www/.bash_profile [root@jenkins www]# echo "PATH=/home/www/sdk/tools/:$PATH" >> /etc/profile.d/sdk.sh [root@jenkins www]# source /etc/profile.d/sdk.sh 我们再下载build-tools 根据你的gradle里面buildToolsVersion 下载相应的版本 显示所有可更新列表 #android list sdk --all 7- Android SDK Build-tools, revision 26.0.3 8- Android SDK Build-tools, revision 26.0.2 9- Android SDK Build-tools, revision 26.0.1 10- Android SDK Build-tools, revision 26 11- Android SDK Build-tools, revision 25.0.3 12- Android SDK Build-tools, revision 25.0.2 13- Android SDK Build-tools, revision 25.0.1 14- Android SDK Build-tools, revision 25 42- SDK Platform Android 8.1.0, API 27, revision 1 43- SDK Platform Android 8.0.0, API 26, revision 2 44- SDK Platform Android 7.1.1, API 25, revision 3 45- SDK Platform Android 7.0, API 24, revision 2 46- SDK Platform Android 6.0, API 23, revision 3 47- SDK Platform Android 5.1.1, API 22, revision 2 选择需要更新的内容 [root@jenkins sdk]# android update sdk -u -a -t 7,8,9,10,42,43,44,45,46,47 查看: [root@jenkins build-tools]# ll total 16 drwxr-xr-x. 5 root root 4096 Jan 18 18:16 26.0.0 drwxr-xr-x. 5 root root 4096 Jan 18 18:15 26.0.1 drwxr-xr-x. 5 root root 4096 Jan 18 18:15 26.0.2 drwxr-xr-x. 5 root root 4096 Jan 18 18:15 26.0.3 [root@jenkins platforms]# ll total 8 drwxr-xr-x. 6 root root 4096 Jan 18 18:17 android-25 drwxr-xr-x. 6 root root 4096 Jan 18 18:16 android-26 三)安装插件 android lint plugin gradle plugin Git Parameter Plug-In Email Extension Plugin Gitlab plugin Branch API Plugin Android Emulator Plugin 四)登录jenkins配置环境变量 1)需要配置的环境变量有Android Home、JDK目录、Gradle目录。首先点击系统管理=>系统设置 ![](https://box.kancloud.cn/054f00ca3516b6725a3ac22e1c5354dc_1002x260.png) ![](https://box.kancloud.cn/bf9c7a30a1219364c06bcdf0fe93574a_1019x210.png) 2) 系统管理---全局工具配置 ![](https://box.kancloud.cn/9e11f6f7104432c651dcf6a25c6849c6_987x236.png) --gradle ![](https://box.kancloud.cn/9e11f6f7104432c651dcf6a25c6849c6_987x236.png)---jdk ![](https://box.kancloud.cn/599da53c92f0434256856dd3042f040f_1001x229.png)--maven 五)配置项目(不带任何参数的) 构建操作 ![](https://box.kancloud.cn/928de39f4f8f764a04d9ba1febd4dc63_700x364.png) 构建后操作 ![](https://box.kancloud.cn/faf59e928aabe121d64410a0dcbf70ea_1145x354.png)