gradle安装与jenkins集成
来源:原创
时间:2020-10-24
作者:脚本小站
分类:Jenkins
Gradle安装
下载:
wget https://downloads.gradle.org/distributions/gradle-5.3-bin.zip
安装:
unzip gradle-5.3-bin.zip -d /usr/local/ cd /usr/local/ ln -sv gradle-5.3/ gradle
环境变量:
cat > /etc/profile.d/gradle.sh <<EOF export GRADLE_HOME=/usr/local/gradle export PATH=$PATH:$GRADLE_HOME/bin EOF source /etc/profile.d/gradle.sh
测试:
[root@jenkins ~]# gradle -v ------------------------------------------------------------ Gradle 5.3 ------------------------------------------------------------ Build time: 2019-03-20 11:03:29 UTC Revision: f5c64796748a98efdbf6f99f44b6afe08492c2a0 Kotlin: 1.3.21 Groovy: 2.5.4 Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018 JVM: 1.8.0_252 (Oracle Corporation 25.252-b09) OS: Linux 3.10.0-1062.el7.x86_64 amd64
常用命令:
gradlew -v 版本号
gradlew clean 删除HelloWord/app目录下的build文件夹
gradlew build 检查依赖并编译打包
gradlew assembleDebug 编译并打Debug包
gradlew assembleRelease 编译并打Release的包
gradlew installRelease Release 模式打包并安装
gradlew uninstallRelease 卸载Release模式包
jenkins集成gradle
jenkins->全局工具配置:
配置:
在jenkins中创建一个测试任务:groovy脚本如下
#!groovy pipeline{ agent{ node{ label "master" } } stages{ stage("gradle test"){ steps{ script{ gradleHome = tool "GRADLE" sh """ ${gradleHome}/bin/gradle -v """ } } } } }
构建测试成功即可。