I'm porting a scripted pipeline to a declarative one.
//Scripted
def myEnv = [:]
stage ('Prepare my env') {
[...]
myEnv = ...
}
stage ('Fancy stuff') {
node() {
withEnv(myEnv} {
// here use what is defined in myEnv
}
}
stage ('Fancy stuff2') {
node() {
withEnv(myEnv} {
// here use what is defined in myEnv
}
}
}
and now in declarative I would like to have
//Declarative
def myEnv = [:]
pipeline {
agent none
stage('Prepare my env') {
steps {
script {
[...]
myEnv = ...
}
}
}
stages {
environment { myEnv }
stage('Fancy stuff') {
[...]
}
stage('Fancy stuff2') {
[...]
}
}
}
when I try to run this, it fails withEnv
"org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: xx: "myEnv" is not a valid environment expression. Use "key = value" pairs with valid Java/shell keys.
"
Fair enough.
What should I do to be able to use declarative environment { } to avoid using the declarative one in every further steps?
Bob.