[英]Groovy read yaml file returns array
yml_1:
server
port: 1023
yml_2:
server
port: 4001
我在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)
}
}
}
}
它在第一个yml中工作正常,URL返回http:// hostname:1023 / info ,但如果对第二个yml文件再次调用checkService(),则返回数组: http:// hostname:[4001] / info
问题出在哪儿?
我用这个解决了
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.