Difference between "echo" and "println" in Jenkinsfile, and clarification of "pipeline steps"

24,185 views
Skip to first unread message

David Karr

unread,
Nov 18, 2016, 11:42:02 AM11/18/16
to Jenkins Users
I see in the "Pipeline Steps" there is "echo".  I don't see "println".  When I execute a Jenkinsfile with a "println" statement, I see "[Pipeline] echo" printed before the output line, as if "println" is just a synonym for "echo".

If I change the statement to use "echo" instead, it appears to do exactly the same.

The other confusion has to do with the semantics of "Pipeline Steps".  I've been informed in several ways that you can't execute "Pipeline Steps" in a @NonCPS-annotated method.  I've also been told that all the choices in the "Snippet Generator" dropdown are pipeline steps. However, I just tested the following pipeline:
node {
    stage
("testing") {
       
def list = ["abc", "def"]
        listIterator
(list)
        listIterator2
(list)
        println
"done."
   
}
}

@NonCPS
def listIterator(List<String> list) {
    list
.each { item -> println "item[${item}]" }
}

@NonCPS
def listIterator2(List<String> list) {
    list
.each { item -> echo "item[${item}]" }
}

Here's the output from running that pipeline:
[Pipeline] {
[Pipeline] stage
[Pipeline] { (testing)
[Pipeline] echo
item[abc]
[Pipeline] echo
item[def]
[Pipeline] echo
item[abc]
[Pipeline] echo
item[def]
[Pipeline] echo
done.
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

In my experience, if you execute a "pipeline step" within a @NonCPS-annotated method, the behavior I see is that it appears to just exit the pipeline at the point where it would have executed that statement.  As you can see, this pipeline managed to get to the last instruction of the pipeline (printing "done"), but the "listIterator2" method has @NonCPS, and it calls "echo", which is a pipeline step.

Brian Ray

unread,
Nov 22, 2016, 2:55:11 PM11/22/16
to Jenkins Users
I've been bitten by @NonCPS and CPS transformed code as well, plus CPS steps ...

In my understanding steps like echo are synchronous and can work inside a @NonCPS method. Even if not recommended. I think asynchronous steps inside @NonCPS loops or most CPS transformed loops wind up causing a silent, mysterious early exit. That's been my experience.

I wish Pipeline would trap these situations, at least logging a warning.
Reply all
Reply to author
Forward
0 new messages