我们创建了一个新的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
答案 0 :(得分:3)
在全局范围内定义var
def rtMaven = ''
pipeline {
agent any
stages {
stage('stage1') {
steps {
script {
rtMaven = Artifactory.newMavenBuild()
}
}
}
}
stage('stage2') {
steps {
script {
echo "$rtMaven"
}
}
}
}