Groovy - Jenkins Pipeline - Groovy CPS doesn't go trough .eachLine method

Viewed 6486

I am trying to run this code inside Jenkins Pipeline script:

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

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

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

The result should be a list of folders at the svn location but what I am getting is an error:

[Pipeline] echo:

1.0.0/

expected to call java.lang.ProcessImpl$ProcessPipeInputStream.eachLine but wound up catching org.jenkinsci.plugins.workflow.cps.CpsClosure2.call

The proc.in.eachLine is causing the issue, as if Groovy finds the first folder on the location but can not handle the rest and reports an error.

1 Answers

This is what worked for me:

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

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

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