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

Nothing is executed after emailextrecipients() when called in method with NonCPS annotation

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • email-ext-plugin
    • None
    • Jenkins 2.89.2, email-ext-plugin 2.61

      With a method calling emailextrecipients() annotated by NonCPS, nothing is executed after that emailextrecipients() call. Example pipeline script and its output below:

      node("master") {
        mail()
      }
      
      @NonCPS
      void mail() {
        def to = emailextrecipients([[$class: 'RequesterRecipientProvider']])
        echo "Recipients: ${to}"
      
        if (to != null && !to.isEmpty()) {
          emailext to: to,
            replyTo: "\$DEFAULT_REPLYTO",
            subject: "\$DEFAULT_SUBJECT",
            body: "\$DEFAULT_CONTENT"
        }
      }
      [Pipeline] node
      Running on Jenkins in /var/lib/jenkins/jobs/Test-Workflow/workspace
      [Pipeline] {
      [Pipeline] emailextrecipients
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

      Without NonCPS the output is:

      [Pipeline] node
      Running on Jenkins in /var/lib/jenkins/jobs/Test-Workflow/workspace
      [Pipeline] {
      [Pipeline] emailextrecipients
      [Pipeline] echo
      Recipients: atikhonova@parallels.com
      [Pipeline] emailext
      Sending email to: atikhonova@parallels.com
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS

          [JENKINS-49230] Nothing is executed after emailextrecipients() when called in method with NonCPS annotation

          from https://github.com/jenkinsci/workflow-cps-plugin/blob/master/README.md#technical-design

          @NonCPS methods may safely use non-Serializable objects as local variables, though they should not accept nonserializable parameters or return or store nonserializable values. You may not call regular (CPS-transformed) methods, or Pipeline steps, from a @NonCPS method

          David van Laatum added a comment - from https://github.com/jenkinsci/workflow-cps-plugin/blob/master/README.md#technical-design @NonCPS  methods may safely use non- Serializable  objects as local variables, though they should not accept nonserializable parameters or return or store nonserializable values. You may not call regular (CPS-transformed) methods, or Pipeline steps, from a  @NonCPS  method

          You also don't need to use emailextrecipients you can pass recipient providers to emailext directly

          David van Laatum added a comment - You also don't need to use emailextrecipients you can pass recipient providers to emailext directly

            davidvanlaatum David van Laatum
            atikhono Anna Tikhonova
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: