Groovy-Jenkins管道-Groovy CPS不会通过.eachLine方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Groovy-Jenkins管道-Groovy CPS不会通过.eachLine方法相关的知识,希望对你有一定的参考价值。

我正在尝试在Jenkins Pipeline脚本中运行此代码:

def getTags = { svnurl ->
    def command = ["svn","ls","${svnurl}"];
    def proc = command.execute()
    proc.waitFor()

    proc.in.eachLine {
        println(it)
    }    
}

getTags('http://svnurlexample.net/');

结果应该是svn位置的文件夹列表,但是我得到的是一个错误:

[管道]回声:

1.0.0 /

预期会调用java.lang.ProcessImpl $ ProcessPipeInputStream.eachLine,但最后捕获org.jenkinsci.plugins.workflow.cps.CpsClosure2.call结束

proc.in.eachLine引起了问题,好像Groovy在该位置找到了第一个文件夹,但无法处理其余文件夹并报告错误。

答案

这对我有用:

@NonCPS
def getTags (svnurl) {
    def command = ["svn","ls","${svnurl}"];
    def proc = command.execute()
    proc.waitFor()

    proc.in.eachLine {
        println(it)
    }    
}

getTags('http://svnurlexample.net/');

以上是关于Groovy-Jenkins管道-Groovy CPS不会通过.eachLine方法的主要内容,如果未能解决你的问题,请参考以下文章