the environment is a declarative block, what you are trying to make is to 
define a bunch of variables with a scriptlet block, this is far away from 
declarative.
The following code make what you want to do

pipeline {
    agent any

    stages {
        stage('test') {
            steps {
               script {
                   [A:1,B:2].each { k, v ->
                       env."${k}" = "${v}"
                   }
                   echo """
                   A = ${env.A}
                   B = ${env.B}
                   """
               }
            }
        }
    }
}

El miércoles, 14 de julio de 2021 a las 17:15:29 UTC+2, 
fakemai...@gmail.com escribió:

> I haven't found any examples of how to do this
>
> instead of this:
>
>     pipeline {
>
>         agent { label 'docker' }
>
>         environment {
>
>             ENV1 = 'default'
>
>             ENV2 = 'default'
>
>         }
>
>
> I want to do this:
>
>     pipeline {
>
>         agent { label 'docker' }
>
>         environment {
>
>             for (env in envs) {
>
>                env.name = env.value
>
>             }
>
>         }
>
>
> maybe I can generate a map before the `pipeline{}` directive and pass it 
> to `environment{}` somehow? I dont want to do this inside of a stage I want 
> this at the top level environment directive for all stages
>

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/731604df-3a72-4c54-ba63-d5626a9e437bn%40googlegroups.com.

Reply via email to