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方法的主要内容,如果未能解决你的问题,请参考以下文章

序言中不允许内容,但序言在运行时可以吗? Groovy,Jenkins,Java,管道,XML [重复]

Jenkins CI 管道脚本不允许使用方法 groovy.lang.GroovyObject

如何在同一个 Jenkins 节点中加载另一个 groovy 脚本?

如何在 Jenkins 声明式管道中创建方法?

Grails:拆分包含管道的字符串

你如何加载一个groovy文件并执行它