Discussion:
Jenkins Pipeline : How can I pass a map obtained from readProperties to withEnv ?
JL 6BerYeti
2016-11-30 13:26:07 UTC
Permalink
Dear All,

I am trying to setup (many) environment variables for a set of stages
within a pipeline by reading a property file and then passing the result to
withEnv.
As far as my understanding is correct, I thought that withEnv waits for a
map, and readProperties returrns a map.
So, I try this :
def localProps=[:]
localProps=["moduleName=Communicator","versionNbr=1.0"]
def pipeProps=readProperties([
defaults : localProps,
file : "Pipeline/lib/tutoFile.properties"
])
echo "${pipeProps}"
withEnv(pipeProps) {
... pipeline stages
}

I am sure that the file is read within pipePros.
But the withEnv step fails with the following error :

java.lang.UnsupportedOperationException: must specify $class with an implementation of interface java.util.List at org.jenkinsci.plugins.structs.describable.DescribableModel.resolveClass(DescribableModel.java:442) at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:371) at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:313) at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:257) at org.jenkinsci.plugins.workflow.steps.StepDescriptor.newInstance(StepDescriptor.java:194) at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:181) at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:126) at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108)

I don't understand what is wrong in the code (as you can imagine, I am not a groovy guru...), and I'd like to know how to get out of there.

Thanks for your help.
J-L
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/7be471c6-df0b-410e-8b5e-31322c931f64%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
thomo5000
2017-07-12 05:33:45 UTC
Permalink
This question is a top search result on Google so I figure it's worth a late
reply.

readProperties returns a map and withEnv expects a list so you'll need to
def map = readProperties file:'env.properties'
def properties = map.collect { key, value -> return key+'='+value }
withEnv(properties)
--
View this message in context: http://jenkins-ci.361315.n4.nabble.com/Jenkins-Pipeline-How-can-I-pass-a-map-obtained-from-readProperties-to-withEnv-tp4861746p4900401.html
Sent from the Jenkins users mailing list archive at Nabble.com.
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1499837625173-4900401.post%40n4.nabble.com.
For more options, visit https://groups.google.com/d/optout.
Loading...