Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jenkins Groovy读取yaml文件返回数组_Jenkins_Groovy_Jenkins Pipeline_Snakeyaml - Fatal编程技术网

Jenkins Groovy读取yaml文件返回数组

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

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