Groovy 读取 yaml 文件 returns 数组

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 returns http://hostname:1023/info, 但如果再次为第二个 yml 文件调用 checkService(),它 returns 数组: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]
}