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

Extended E-mail Notification pre-send script can not use getEnvVars method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Major Major
    • email-ext-plugin
    • None
    • Jenkins+Mac+Groovy

      Hi guys, there have some issue i don't know how to sloved it.

      I try to use email-ext-plugin send email to notify the failure item. and write a groovy script to get Global variables。

      import groovy.json.JsonSlurper
      
      def var = build.getEnvVars()
      def emailContent = msg.getContent().getBodyPart(0).getContent()
      def jobname = var.get("JOB_NAME")
      def build_url = var.get("BUILD_URL")
      def emailString = """
      $emailContent
      JOB_NAME:$jobname
      Check console output at $build_url to view the results.
      """
      msg.setContent(emailString.toString(), "text/plain")

       

      and then, it is work normal on yesterday, but this morning, it can not send out email, and i found the jenkins log:

      Executing pre-send script
      class hudson.model.FreeStyleBuildPre-send script tried to access secured objects: Scripts not permitted to use method hudson.model.Run getEnvVars
      ERROR: Could not send email as a part of the post-build publishers.
      org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method hudson.model.Run getEnvVars
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectMethod(StaticWhitelist.java:175)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:137)
      	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:153)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:157)
      	at org.kohsuke.groovy.sandbox.impl.Checker$checkedCall$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 Script1.run(Script1.groovy:4)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.run(GroovySandbox.java:141)
      	at hudson.plugins.emailext.ExtendedEmailPublisher.executeScript(ExtendedEmailPublisher.java:627)
      	at hudson.plugins.emailext.ExtendedEmailPublisher.executePresendScript(ExtendedEmailPublisher.java:573)
      	at hudson.plugins.emailext.ExtendedEmailPublisher.sendMail(ExtendedEmailPublisher.java:456)
      	at hudson.plugins.emailext.ExtendedEmailPublisher._perform(ExtendedEmailPublisher.java:441)
      	at hudson.plugins.emailext.ExtendedEmailPublisher.perform(ExtendedEmailPublisher.java:349)
      	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:736)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:682)
      	at hudson.model.Build$BuildExecution.cleanUp(Build.java:196)
      	at hudson.model.Run.execute(Run.java:1784)
      	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      	at hudson.model.ResourceController.execute(ResourceController.java:97)
      	at hudson.model.Executor.run(Executor.java:419
      

       How can I deal with this problem?

            qwerty_i ning yuan
            qwerty_i ning yuan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: