Hi,

I'm porting a scripted pipeline to a declarative one.

I used to have something like this:
//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?

Thank you,

Bob.

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/571b31d3-fbb6-4c4e-a515-50bf6ee755fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to