I am converting the key=value string Groovy Map. Then after some changes, returning back the serialize object. Example String --> dlpxDcTags = "OWNER=test,PROJECT=test2,COSTCENTER=1234,TEAM=devops"
parseDcenterTags(dlpxDcTags){
Map tags = [:]
tags += dlpxDcTags.replaceAll('\\[|\\]', '').split(',').collectEntries { entry ->
def pair = entry.split('=')
[(pair.first().trim()): pair.last().trim()]
return tags
}
}
def createDcenterTags(dlpxDcTags=null) {
// Values passed from the environment of the user takes precedence
tags = parseDcenterTags(dlpxDcTags)
if (tags) {
if (!(tags.get('PROJECT'))) {
tags['PROJECT'] = env.JOB_NAME
}
if (!tags.get('OWNER')) {
// not supplied via dlpxDcTags
tags['OWNER'] = env.BUILD_USER_EMAIL
}
}
else {
tags['PROJECT'] = env.JOB_NAME
tags['OWNER'] = env.BUILD_USER_EMAIL
}
return serializeDcenterTags(tags)
}
def serializeDcenterTags(tags){
dlpxDcTags = {
tags.collect { /$tags.key="$tags.value"/ } join ","
}
return dlpxDcTags
}
Facing issue:
After lot of reading and trying different ways, the very simple thing which worked for me was doing the serialization in the same method instead of defining and calling it from another method.
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.