Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-56304

jiraAddComment terminates the step prematurely

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Not A Defect
    • jira-steps-plugin
    • None
    • jenkins 2.150.3
      Jira Pipeline Steps 1.4.4

    Description

      At the end of my pipeline, I am iterating the changeSets and the commits therein looking for strings that match Jira tickets, in order to update all Jira's with code present in a build.  In theory, this could result in multiple Jiras needing to be updated, so this is done in a loop, potentially making multiple calls to jiraAddComment(..).   However, the entire step stops (seems to return success) once the first jiraAddComment is completed.

      See attached source and output.  Following call to jiraAddComment(..), the subsequent echo should fire indicating that execution flow has continued.  The first jiraAddComment appears in the log (and the comment appears in Jira).  However, no subsequent echos in the log.  No subsequent call to jiraAddComment in the log, and no subsequent comments in Jira. 

      It is as-if execution stops at the first call to jiraAddComment

      Attachments

        1. output.txt
          1 kB
        2. output-final.txt
          4 kB
        3. output-stubCall.txt
          4 kB
        4. output-truncatedCall.txt
          2 kB
        5. source.txt
          4 kB

        Activity

          jbennett20912 Jeffrey Bennett created issue -
          jbennett20912 Jeffrey Bennett made changes -
          Field Original Value New Value
          Attachment output.txt [ 46189 ]
          Attachment source.txt [ 46190 ]
          jbennett20912 Jeffrey Bennett made changes -
          Description At the end of my pipeline, I am iterating the changeSets and the commits therein looking for strings that match Jira tickets, in order to update all Jira's with code present in a build.  In theory, this could result in multiple Jiras needing to be updated, so this is done in a loop, potentially making multiple calls to jiraAddComment(..).   However, the entire step stops (seems to return success) once the first jiraAddComment is completed. At the end of my pipeline, I am iterating the changeSets and the commits therein looking for strings that match Jira tickets, in order to update all Jira's with code present in a build.  In theory, this could result in multiple Jiras needing to be updated, so this is done in a loop, potentially making multiple calls to jiraAddComment(..).   However, the entire step stops (seems to return success) once the first jiraAddComment is completed.

          See attached source and output.  Following call to jiraAddComment(..), the subsequent echo should fire indicating that execution flow has continued.  The first jiraAddComment appears in the log (and the comment appears in Jira).  However, no subsequent echos in the log.  No subsequent call to jiraAddComment in the log, and no subsequent comments in Jira. 

          It is as-if execution stops at the first call to jiraAddComment
          nrayapati Naresh Rayapati added a comment - - edited

          I doubt it is either @NonCPS annotation or the msg.findAll, cause not all the steps can be invoked in @NonCPS method and also not all the groovy syntax supported in Jenkins pipeline especially those loops and methods on collections. 

          Can you try:

          • Just replace jiraAddComment with another echo, if it went through the loop
          • Try removing the @NonCPS annotation.
          • or just try couple of jiraAddComment steps in sequence outside the loop 

           

          nrayapati Naresh Rayapati added a comment - - edited I doubt it is either @NonCPS annotation or the msg.findAll , cause not all the steps can be invoked in @NonCPS method and also not all the groovy syntax supported in Jenkins pipeline especially those loops and methods on collections.  Can you try: Just replace jiraAddComment with another echo, if it went through the loop Try removing the @NonCPS annotation. or just try couple of jiraAddComment steps in sequence outside the loop   

          Experiment #1:   Remove @NonCPS - Failed

          The stage now fails (red instead of green stage).  The log messages indicate it went into jiraAddComment and then hit a "Failed in branch Update Jira".  There is a stack-trace later in the log that indicates "java.io.NotSerializableException: hudson.plugins.git.GitChangeSetList"

           

          jbennett20912 Jeffrey Bennett added a comment - Experiment #1:   Remove @NonCPS - Failed The stage now fails (red instead of green stage).  The log messages indicate it went into jiraAddComment and then hit a "Failed in branch Update Jira".  There is a stack-trace later in the log that indicates "java.io.NotSerializableException: hudson.plugins.git.GitChangeSetList"  
          jbennett20912 Jeffrey Bennett made changes -
          Attachment output-stubCall.txt [ 46195 ]

          Experiment #2: (restored @NonCPS) replace invocation of jiraAddComment with echo instead - qualified success

          The Stage succeeds.  The log messages indicate it goes through the expected pathways - looping and recursing as expected.  Message payload looks correct.  No errors.   Obviously, we are NOT sending anything to Jira with this approach, but it verifies syntax.   See output-stubCall.txt for details

          This seems to firmly point the finger at the call to jiraAddComment as the culprit

           

           

          jbennett20912 Jeffrey Bennett added a comment - Experiment #2: (restored @NonCPS) replace invocation of jiraAddComment with echo instead - qualified success The Stage succeeds.  The log messages indicate it goes through the expected pathways - looping and recursing as expected.  Message payload looks correct.  No errors.   Obviously, we are NOT sending anything to Jira with this approach, but it verifies syntax.   See output-stubCall.txt for details This seems to firmly point the finger at the call to jiraAddComment as the culprit    
          jbennett20912 Jeffrey Bennett made changes -
          Attachment output-truncatedCall.txt [ 46196 ]
          nrayapati Naresh Rayapati added a comment - - edited

          With Experiment #1, you got to deal with the variables those are non serializable in that method to get through that. And from the design you can't invoke pipeline steps from a method with @NonCPS annotation, I don't see any problem with the jiraAddComment step. 

          You may not call regular (CPS-transformed) methods, or Pipeline steps, from a @NonCPS method, so they are best used for performing some calculations before passing a summary back to the main script. 

          nrayapati Naresh Rayapati added a comment - - edited With Experiment #1, you got to deal with the variables those are non serializable in that method to get through that. And from the design you can't invoke pipeline steps from a method with @NonCPS annotation, I don't see any problem with the jiraAddComment step.  https://github.com/jenkinsci/workflow-cps-plugin#technical-design   You may not call regular (CPS-transformed) methods, or Pipeline steps, from a  @NonCPS  method, so they are best used for performing some calculations before passing a summary back to the main script. 

          Experiment #3: Complete replacement of the method with a trivial invocation that invokes jiraAddComment twice - Failure (in same manner as original issue)

          See output-truncatedCall.txt.   The stage succeeds (green and not red).  However, logs indicate that we only invoked the first jiraAddComment and no further steps were performed (like the original bug).   Inspection in Jira confirms that only the FIRST jiraAddComment was received.

          jbennett20912 Jeffrey Bennett added a comment - Experiment #3: Complete replacement of the method with a trivial invocation that invokes jiraAddComment twice - Failure (in same manner as original issue) See output-truncatedCall.txt.   The stage succeeds (green and not red).  However, logs indicate that we only invoked the first jiraAddComment and no further steps were performed (like the original bug).   Inspection in Jira confirms that only the FIRST jiraAddComment was received.
          nrayapati Naresh Rayapati added a comment - - edited

          But the code is still in @NonCPS method with Experiment #3, try invoking these steps outside that method.

          https://jenkins.io/blog/2017/02/01/pipeline-scalability-best-practice/

          3. c

          @NonCPS functions should not use Pipeline steps internally, however you can store the result of a Pipeline step to a variable and use it that as the input to a @NonCPS function.
          
          Gotcha: It’s not guaranteed that use of a step will generate an error (there is an open RFE to implement that), but you should not rely on that behavior. You may see improper handling of exceptions, in particular.
          
          nrayapati Naresh Rayapati added a comment - - edited But the code is still in @NonCPS method with Experiment #3, try invoking these steps outside that method. https://jenkins.io/blog/2017/02/01/pipeline-scalability-best-practice/ 3. c @NonCPS functions should not use Pipeline steps internally, however you can store the result of a Pipeline step to a variable and use it that as the input to a @NonCPS function. Gotcha: It’s not guaranteed that use of a step will generate an error (there is an open RFE to implement that), but you should not rely on that behavior. You may see improper handling of exceptions, in particular.

          Experiment #4: calling jiraAddComment twice directly from steps(), i.e. no method call, definitely works.  Just verified that

          jbennett20912 Jeffrey Bennett added a comment - Experiment #4: calling jiraAddComment twice directly from steps(), i.e. no method call, definitely works.  Just verified that

          yeah, as I mentioned in the above comments, pipeline steps has be outside the @NonCPS function. 

          nrayapati Naresh Rayapati added a comment - yeah, as I mentioned in the above comments, pipeline steps has be outside the @NonCPS function. 

          I'm inferring that if I use the @NonCPS method to build an array of Jiras to update (ID + Comment), pass the array back to the stage, iterate and call jiraAddComment for each element in the array (from the stage), it would work.  I think?

          My groovy skills are weak.  Built an array in the method, but cannot figure out how to get it back to the stage

           

           

           

          jbennett20912 Jeffrey Bennett added a comment - I'm inferring that if I use the @NonCPS method to build an array of Jiras to update (ID + Comment), pass the array back to the stage, iterate and call jiraAddComment for each element in the array (from the stage), it would work.  I think? My groovy skills are weak.  Built an array in the method, but cannot figure out how to get it back to the stage      
          nrayapati Naresh Rayapati made changes -
          Priority Critical [ 2 ] Minor [ 4 ]
          jbennett20912 Jeffrey Bennett made changes -
          Attachment output-final.txt [ 46197 ]

          OK resolved it - many thanks.   Indeed, you have to build an array of Jiras to update in a method, then do the updating back in the stage (inside a script marker).

          I added my final code to output-final.txt in the hopes maybe it will benefit the next person.

          nrayapati  Thank you for the help!

          Issue can be closed

          jbennett20912 Jeffrey Bennett added a comment - OK resolved it - many thanks.   Indeed, you have to build an array of Jiras to update in a method, then do the updating back in the stage (inside a script marker). I added my final code to output-final.txt in the hopes maybe it will benefit the next person. nrayapati   Thank you for the help! Issue can be closed
          jbennett20912 Jeffrey Bennett made changes -
          Resolution Not A Defect [ 7 ]
          Status Open [ 1 ] Fixed but Unreleased [ 10203 ]

          work-around found.  Invocation of step from method is illegal.

          jbennett20912 Jeffrey Bennett added a comment - work-around found.  Invocation of step from method is illegal.
          jbennett20912 Jeffrey Bennett made changes -
          Status Fixed but Unreleased [ 10203 ] Closed [ 6 ]

          No problem! Thank you for using this plugin. 

          nrayapati Naresh Rayapati added a comment - No problem! Thank you for using this plugin. 
          nrayapati Naresh Rayapati made changes -
          Status Closed [ 6 ] Fixed but Unreleased [ 10203 ]
          nrayapati Naresh Rayapati made changes -
          Status Fixed but Unreleased [ 10203 ] Closed [ 6 ]

          People

            nrayapati Naresh Rayapati
            jbennett20912 Jeffrey Bennett
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: