I have a constants.groovy like below
import groovy.transform.Field
@Field
def emailDistributionList = ['catalogSuccess':'ccc@ff.com, fff.ddd@gmail.com', 'catalogFailure':'fffee@ofr.com']
return this;
Now I have a Jenkins pipeline main script as below
node ('node1') {
stage("Read Constants") {
script {
def constants = evaluate readTrusted('jenkins_pipeline/constants.groovy')
def catalogDistributionList = "${constants.emailDistributionList}"
echo "${catalogDistributionList}"
def successList = "${catalogDistributionList.catalogSuccess}"
echo "${successList}"
}
}
}
Now first echo
prints the Field
from constants file sucessfully. But when I try read a key from that and print it using the second echo
it throws error
groovy.lang.MissingPropertyException: No such property: catalogSuccess for class: org.codehaus.groovy.runtime.GStringImpl
I think it's reading the Field
from constants.groovy
as a String
and not a Map
?
I figured it out.
We cannot read the map
to a variable and then get the key
. Instead everything has to be done in one shot.
It has to be done this way
def catalogDistributionList = "${constants.emailDistributionList.catalogSuccess}"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.