我有以下常規,
def terraformOutputLocal(Map params) {
terraformOutputAttributes = "terraform output".execute().text
}
def terraformOutputValues = terraformOutputLocal()
println terraformOutputValues
以上將給我輸出,
billing_mode = "PAY_PER_REQUEST"
name = "testing-table"
stream_view_type = "NEW_AND_OLD_IMAGES"
我想將此輸出作為如下地圖,
[billing_mode:PAY_PER_REQUEST, name:testing-pipeline-test-table, stream_view_type:NEW_AND_OLD_IMAGES]
謝謝
uj5u.com熱心網友回復:
您可以拆分換行符,然后拆分每一行=并將它們收集回地圖:
def terraformOutputLocal(Map params) {
terraformOutputAttributes = "terraform output".execute().text
.split('\n')*.split(' = ').collectEntries()
}
要從字串中洗掉雙引號,您可以執行以下操作:
def terraformOutputLocal(Map params) {
terraformOutputAttributes = "terraform output".execute().text
.split('\n')*.split(' = ')*.toList()
.collectEntries { a, b -> [a, b[0] == '"' ? b[1..-2] : b] }
}
uj5u.com熱心網友回復:
對于這種格式,您可以使用ConfigSlurper
def terraformOutputValues = '''
billing_mode = "PAY_PER_REQUEST"
name = "testing-table"
stream_view_type = "NEW_AND_OLD_IMAGES"
'''
def c = new ConfigSlurper().parse(terraformOutputValues)
assert c.billing_mode == 'PAY_PER_REQUEST'
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/441345.html
上一篇:使用單獨的字典更改字典鍵?
