Groovy read yaml file возвращает массив - PullRequest
0 голосов
/ 03 июля 2018

yml_1:

server
  port: 1023

yml_2:

server
  port: 4001

Я использую readYaml в Jenkins для чтения файла 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, но он возвращает массив, если снова вызывает checkService () для второго файла yml: http://hostname:[4001]/info

Где проблема?

1 Ответ

0 голосов
/ 13 июля 2018

Я использую это решено

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]
}
...