我们创建一个新的 maven 构建:
def rtMaven = Artifactory.newMavenBuild()
现在我们想在与当前阶段不同的阶段重用这个 rtMaven;
就像下面的代码:
pipeline {
agent any
...
stages {
stage('stage1') {
steps {
script {
def rtMaven = Artifactory.newMavenBuild()
}
}
stage('stage2') {
steps {
script {
//REUSE rtMaven (now it's unknown)
}
}
}
}
是否可以重用rtMaven而无需在第二阶段再次重新定义它?
现在我们有一个错误,如:
groovy.lang.MissingPropertyException: No such property: rtMaven for class: groovy.lang.Binding
最佳答案
在全局范围内定义 var
def rtMaven = ''
pipeline {
agent any
stages {
stage('stage1') {
steps {
script {
rtMaven = Artifactory.newMavenBuild()
}
}
}
}
stage('stage2') {
steps {
script {
echo "$rtMaven"
}
}
}
}
关于maven - 在 Jenkins 声明性管道的不同阶段重用对象/属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47155326/