Jira comment command exiting loop in Jenkinsfile

369 views
Skip to first unread message

Matthew Harrison

unread,
Aug 7, 2016, 8:35:02 PM8/7/16
to Jenkins Users
Hi, I'm using Jenkins 2.14, and am implementing a build with a Jenkinsfile.  As part of that build I'm looking to update Jira with some additional comments as to the output of the build.

The piece that is behaving strangely is this:

def previousJiraBuildAction = baseBuild.getAction(JiraBuildAction.class)
if (previousJiraBuildAction != null) {
    echo
"issues to log: " + previousJiraBuildAction.issues.length
   
for (int i=0; i < previousJiraBuildAction.issues.length; i++ ) {
       
//create a Jira Comment with the version number for the Issues found previously
       
try {
            echo
"adding comment to " + previousJiraBuildAction.issues[i].id
            jiraComment
([issueKey : previousJiraBuildAction.issues[i].id, body : "New build created for ${component} with version ${version}"])
       
} catch (Exception e) {
           
//log error and carry on
           
//this only seems to work if its not in a NonCPS method, otherwise the jiraComment call exits the loop, without an error
            echo
"error " + e
       
}
   
}
    echo
"after loop"
}

Prior to this method running a JiraIssueUpdater step has run, which can add several issues to the JiraBuildAction.

If I annotate the method this is running in with @NonCPS the loop gets to the first jiraComment, and then exits with no error message.  With the code like this I get a java.io.NotSerializableException, but it does seem to loop through all the issues and update them.

Are there any suggestions/thoughts as to why it might be silently exiting the loop?

Thanks in advance,

Matt

Baptiste Mathus

unread,
Aug 8, 2016, 7:42:16 AM8/8/16
to jenkins...@googlegroups.com

Probably https://issues.jenkins-ci.org/browse/JENKINS-31314

It's currently unsupported to call DSL steps from NonCPS code.

Cheers


--
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 jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/0d9fde56-abe3-4ade-a2e7-72e3cd38f418%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Baptiste Mathus

unread,
Aug 8, 2016, 7:55:58 AM8/8/16
to jenkins...@googlegroups.com

And I think you can remove the 'currently' from my sentence. What's 'currently' definitely missing is that it should immediately fail with a clear error.

Indeed, what Continuation passing style (CPS) gives you is the durability of your pipeline.
Said differently, it means each step (in the general meaning) is checkpointed, in case of a crash for example to be able to restart from where it left.
So calling non CPS code from CPS one is going to be something like "OK, call that thing if you will, I'll stay there waiting for you. If you never back, well we'll restart from where I am now" (which is BTW already typically the case each time you call a shell step and so on: if your shell script takes one hour of complex things and fail, it will simply get back to the beginning of it. Not where that script left).

If you think about it, the other way, calling CPS code from non CPS is probably weirder: you are in a non serializable place (non CPS code), and you call something designed to take care of what it did and where it left.

Note this is my understanding of all that. Jesse will probably correct me soon if I'm wrong :).

Matthew Harrison

unread,
Aug 8, 2016, 3:40:58 PM8/8/16
to Jenkins Users, m...@batmat.net
Ah, OK, that makes sense, thank you.  Now you've pointed out whats going on with the CPS code I can see why there is a problem.  Hopefully some way can be found of letting people know (i.e. an error) when this situation occurs - it was very weird just having the loop stop :)

I think with the pointers you've given me I should be able to sort out this code now.

Thanks,

Matt
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages