准备工作
- 下载地址:https://gradle.org/releases/
安装和配置环境变量
- 将压缩包解压到/usr/local/目录下
unzip gradle-8.7-bin.zip -d /usr/local/
- 找到gradle的安装目录/usr/local/gradle-8.7
- 编辑/etc/vi /etc/profileprofile配置环境变量(这是centos)source该文件
vi /etc/profile
source /etc/profile
- 查看gradle是否正确安装
gradle -v
jenkins配置
- 进入“系统管理” --> “全局工具配置” --> “Gradle安装”
- 验证是否配置成功
#!groovy
/*
演示mvn集成到jenkins 流水线中的用法
*/
string buildShell = "$BUILD_SHELL"
pipeline{agent {node {label "$CI_NODE"}}stages{stage("mvn build"){steps{script{mvnHome = tool "MVN"sh "$mvnHome/bin/mvn ${buildShell}"}}}stage("gradle build"){steps{script{gradleHome = tool "GRADLE"sh "$gradleHome/bin/gradle ${buildShell}"}}}stage("ant build"){steps{script{antHome = tool "ANT"sh "$antHome/bin/ant ${buildShell}"}}}}
}