读取Jenkins Pipeline中的yaml行号



如何获取jenkins管道中yml文件的行号

我能得到它使用groovy

def yaml =new  File ('C:/Users/senthiln-1/yaml.yml')
yaml.text.lines().eachWithIndex { String line, int lineNo ->
if (line.contains('key1')) {
println "Found matching $line on line $lineNo"
}
}

但是如何在Jenkins pipeline中获得相同的内容

node {
datas = readYaml file: 'release.yml'
}

检查以下代码。

def data = readFile file: 'test.yml'
data.split('n').eachWithIndex { line, i ->
if (line.contains('key3')) {
println "Found matching $line on line $i"
}

}

最新更新