Jenkins Groovy读取yaml文件返回数组
yml_1: yml_2:Jenkins Groovy读取yaml文件返回数组,jenkins,groovy,jenkins-pipeline,snakeyaml,Jenkins,Groovy,Jenkins Pipeline,Snakeyaml,yml_1: yml_2: server port: 1023 我在Jenkins中使用readYaml读取YAML文件: server port: 4001 它在第一个yml中运行良好,url返回, 但如果对第二个yml文件再次调用checkService(),则返回数组: 问题在哪里?我用这个解决了 void checkService(waitTime) { def conf = readYaml file: "./${CURRENT_STAGE}/src/main/re
server
port: 1023
我在Jenkins中使用readYaml
读取YAML文件:
server
port: 4001
它在第一个yml中运行良好,url返回,
但如果对第二个yml文件再次调用checkService(),则返回数组:
问题在哪里?我用这个解决了
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)
}
}
}
}
首先尝试读取第二个文件,看看问题是否发生……如果没有,则说明第二个yaml文件写入错误,可能是逗号或额外的空格?您的yaml文件无效。在
服务器之后
必须有一个:
@daggett这是一个打字错误,我的yml是正确的。
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]
}