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.
@NonCPS
, or this may be because theexecute
method will always be from the Jenkins master (this code seems build agent independent, but just in case something from the env is impacting here)..eachLine
is one of the methods that is not supported in CPS context. To annotategetTags
with@NonCPS
, as Matt suggested, you have to turn it into a function.