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 
<https://issues.jenkins-ci.org/browse/JENKINS-27421?focusedCommentId=241522&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-241522>.
 
That's been my experience.

I wish Pipeline would trap these situations, at least logging a warning.

On Friday, November 18, 2016 at 8:42:02 AM UTC-8, David Karr wrote:
>
> 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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/5578946d-adfb-4b2e-873e-5ed6223b95cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to