[英]Groovy read yaml file returns array
yml_1: yml_1:
server
port: 1023
yml_2: yml_2:
server
port: 4001
I use readYaml
in Jenkins to read the YAML file: 我在Jenkins中使用readYaml
来读取YAML文件:
void checkService(waitTime) {
def conf = readYaml file: "./${CURRENT_STAGE}/src/main/resources/${CONF_NAME}"
String port = conf.server.port.toString()
timeout(waitTime) {
waitUntil {
script {
def r = sh script: "wget -q http://${HOST_NAME}:${port}/info -O /dev/null", returnStatus: true
return (r == 0)
}
}
}
}
It works fine in first yml, the url returns http://hostname:1023/info , but it returns array if calls checkService() again for second yml file: http://hostname:[4001]/info 它在第一个yml中工作正常,URL返回http:// hostname:1023 / info ,但如果对第二个yml文件再次调用checkService(),则返回数组: http:// hostname:[4001] / info
Where is the problem? 问题出在哪儿?
I use this solved 我用这个解决了
def conf = readYaml file: "${CONF_NAME}"
String port = ""
if ( conf.server.port instanceof Integer ) {
port = conf.server.port
}
if ( conf.server.port instanceof ArrayList ) {
port = conf.server.port[0]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.