We create a new maven build:
def rtMaven = Artifactory.newMavenBuild()
Now we want to reuse this rtMaven in a different stage than the current one; like in the code below:
pipeline {
agent any
...
stages {
stage('stage1') {
steps {
script {
def rtMaven = Artifactory.newMavenBuild()
}
}
stage('stage2') {
steps {
script {
//REUSE rtMaven (now it's unknown)
}
}
}
}
Is it possible to reuse the rtMaven without redefining it again in the second stage?
Now we have an error like:
groovy.lang.MissingPropertyException: No such property: rtMaven for class: groovy.lang.Binding
You can also mix and match node { stage {..}} and stage { node {..}} within your pipeline codes. By design (in Jenkins, as well as in the concept of continuous delivery), stages do not execute in parallel. Only the steps within a single stage are executed in parallel.
Jenkins Pipeline allows you to compose multiple steps in an easy way that can help you model any sort of automation process. Think of a "step" like a single command which performs a single action. When a step succeeds it moves onto the next step. When a step fails to execute correctly the Pipeline will fail.
Define the var in global scope
def rtMaven = ''
pipeline {
agent any
stages {
stage('stage1') {
steps {
script {
rtMaven = Artifactory.newMavenBuild()
}
}
}
stage('stage2') {
steps {
script {
echo "$rtMaven"
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With