• Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • email-ext-plugin
    • None
    • Jenkins 2.60.3

      Trying to use the emailext pipeline step, with the presendScript argument. Step and traceback are further down.

      Seems to complain that it can't get the result property off of the build object. Isn't build supposed to be an included item in the presend script?

      emailext attachLog: true,
      body: 'You can see the console output at $BUILD_URL.',
      compressLog: true,
      recipientProviders: [[$class: 'CulpritsRecipientProvider'],
      [$class: 'DevelopersRecipientProvider']],
      presendScript: '''if (build.result.toString().equals("FAILURE"))

      { msg.addHeader("X-Priority", "1 (Highest)"); msg.addHeader("Importance", "High"); } cancel = build.result.toString().equals("ABORTED");''', subject: 'Final status for Build # $BUILD_NUMBER of $PROJECT_NAME is $BUILD_STATUS!', to: 'bcl@nclasters.org' }

      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] emailext
      Request made to compress build log
      java.lang.NullPointerException: Cannot get property 'result' on null object
      at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60)
      at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:456)
      at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:284)
      at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:286)
      at org.kohsuke.groovy.sandbox.impl.Checker$checkedGetProperty$1.callStatic(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:230)
      at Script1.run(Script1.groovy:1)
      at hudson.plugins.emailext.ExtendedEmailPublisher.executeScript(ExtendedEmailPublisher.java:623)
      at hudson.plugins.emailext.ExtendedEmailPublisher.executePresendScript(ExtendedEmailPublisher.java:573)
      at hudson.plugins.emailext.ExtendedEmailPublisher.sendMail(ExtendedEmailPublisher.java:456)
      at hudson.plugins.emailext.EmailExtStep$EmailExtStepExecution.run(EmailExtStep.java:224)
      at hudson.plugins.emailext.EmailExtStep$EmailExtStepExecution.run(EmailExtStep.java:163)
      at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
      at hudson.security.ACL.impersonate(ACL.java:260)
      at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:748)

          [JENKINS-46485] Pre-send script not working in extemail step

          Matteo Turra added a comment -

          I get the same error groovy.lang.MissingPropertyException: No such property: currentBuild for class: Script1 with

          presendScript: '''if ((currentBuild != null) && ("FAILURE".equals(currentBuild.currentResult)))

          Unknown macro: { msg.addHeader("X-Priority", "1 (Highest)"); msg.addHeader("Importance", "High"); }

          ;

          Matteo Turra added a comment - I get the same error groovy.lang.MissingPropertyException: No such property: currentBuild for class: Script1 with presendScript: '''if ((currentBuild != null) && ("FAILURE".equals(currentBuild.currentResult))) Unknown macro: { msg.addHeader("X-Priority", "1 (Highest)"); msg.addHeader("Importance", "High"); } ;

          Alex Earl added a comment -

          For pipeline, you should use run instead of build in presendScripts.

          Alex Earl added a comment - For pipeline, you should use run instead of build in presendScripts.

          John Kuzniar added a comment -

          Could the documentation in the wiki be updated?  If pipeline is just the exception, at least make a note of this.  This information would have saved me a lot of time, so I'm sure it would be valuable to others.  Thanks.

          Pre-send Script

          The pre-send script is a feature which allows you to write a script that can modify the MimeMessage object prior to sending. This would allow adding custom headers, modifying the body, etc. Predefined variables include:

          • msg - the MimeMessage object which can be modified
          • logger - a PrintStream and will write to the job's log. 
          • build - the build this message belongs to
          • cancel - a boolean, which when set to true will cancel the sending of the email

          John Kuzniar added a comment - Could the documentation in the wiki be updated?  If pipeline is just the exception, at least make a note of this.  This information would have saved me a lot of time, so I'm sure it would be valuable to others.  Thanks. Pre-send Script The pre-send script is a feature which allows you to write a script that can modify the  MimeMessage  object prior to sending. This would allow adding custom headers, modifying the body, etc. Predefined variables include: msg - the MimeMessage object which can be modified logger - a PrintStream and will write to the job's log.  build - the build this message belongs to cancel - a boolean, which when set to true will cancel the sending of the email

          Alex Earl added a comment -

          Done

          Alex Earl added a comment - Done

          John Kuzniar added a comment -

          Thank you.

          John Kuzniar added a comment - Thank you.

            davidvanlaatum David van Laatum
            bclaster Brent Laster
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: