Gradle集成Jenkinsfile有两种方法
- 第一种过变量名和变量值的方式定义好构建工具
- Jenkinsfile中使用: 如上图所示,我定义的Gradle变量名称为Gradle,接下来在Jenkinsfile中使用tool获取变量值。如下
#!groovy
pipeline{
agent { node { label "master"}}
stages{
stage("mavenBuild"){
steps{
script{
mvnHome = tool 'M2'
sh "${mvnHome}/bin/mvn clean package -Dmaven.test.skip=true "
}
}
}
stage("antBuild"){
steps{
script{
antHome = '/usr/local/apache-ant-1.9.15'
sh "${antHome}/bin/ant -v "
}
}
}
stage("GradleBuild"){
steps{
script{
antHome = tool 'Gradle'
sh "${antHome}/bin/gradle -v "
}
}
}
}
}
- 由于ant是在做测试,有异常,可以暴漏出异常并跳过。
#!groovy
pipeline{
agent { node { label "master"}}
stages{
stage("mavenBuild"){
steps{
script{
mvnHome = tool 'M2'
sh "${mvnHome}/bin/mvn clean package -Dmaven.test.skip=true "
}
}
}
stage("antBuild"){
steps{
script{
try {
antHome = '/usr/local/apache-ant-1.9.15'
sh "${antHome}/bin/ant -v "
} catch(e){
println(e)
}
}
}
}
stage("GradleBuild"){
steps{
script{
antHome = tool 'Gradle'
sh "${antHome}/bin/gradle -v "
}
}
}
}
}
- 第二种Jenkinsfile中定义其实跟我们在上面的系统中定义是一样的,我们只需要将变量名和值直接定义在文件中。然后直接调用。
#!groovy
pipeline{
agent { node { label "master"}}
stages{
stage("mavenBuild"){
steps{
script{
mvnHome = tool 'M2'
sh "${mvnHome}/bin/mvn clean package -Dmaven.test.skip=true "
}
}
}
stage("antBuild"){
steps{
script{
try {
antHome = '/usr/local/apache-ant-1.9.15'
sh "${antHome}/bin/ant -v "
} catch(e){
println(e)
}
}
}
}
stage("GradleBuild"){
steps{
script{
antHome = '/usr/local/gradle-5.3'
sh "${antHome}/bin/gradle -v "
}
}
}
}
}
继续阅读
- 我的QQ
- QQ扫一扫
-
- 我的头条
- 头条扫一扫
-
评论