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

EnvInject converts all exception types into EnvInjectException

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • envinject-plugin
    • None

      When running an EnvInject wrapper script, the EnvInject plugin seems to catch all  exception types, turning them into EnvInject exceptions.  I'd prefer to be able to raise a hudson.AbortException, to abort a job cleanly.

       

      https://github.com/jenkinsci/envinject-plugin/blob/f7e90cd296fb730666ea11bc581c10434d2dd37e/src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectEnvVars.java#L231

       
      ERROR: SEVERE ERROR occurs
      org.jenkinsci.lib.envinject.EnvInjectException: Failed to evaluate the script
      at org.jenkinsci.plugins.envinject.service.EnvInjectEnvVars.executeGroovyScript(EnvInjectEnvVars.java:232)
      at org.jenkinsci.plugins.envinject.EnvInjectListener.setUpEnvironmentJobPropertyObject(EnvInjectListener.java:187)
      at org.jenkinsci.plugins.envinject.EnvInjectListener.setUpEnvironment(EnvInjectListener.java:49)
      at hudson.model.AbstractBuild$AbstractBuildExecution.createLauncher(AbstractBuild.java:542)
      at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:462)
      at hudson.model.Run.execute(Run.java:1815)
      at hudson.matrix.MatrixBuild.run(MatrixBuild.java:323)
      at hudson.model.ResourceController.execute(ResourceController.java:97)
      at hudson.model.Executor.run(Executor.java:429)
      Caused by: hudson.AbortException: CUSTOM ABORT MESSAGE HERE
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
      at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77)
      at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
      at org.kohsuke.groovy.sandbox.impl.Checker$3.call(Checker.java:200)
      at org.kohsuke.groovy.sandbox.GroovyInterceptor.onNewInstance(GroovyInterceptor.java:42)
      at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onNewInstance(SandboxInterceptor.java:146)
      at org.kohsuke.groovy.sandbox.impl.Checker$3.call(Checker.java:197)
      at org.kohsuke.groovy.sandbox.impl.Checker.checkedConstructor(Checker.java:202)
      at org.kohsuke.groovy.sandbox.impl.Checker$checkedConstructor$3.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:214)
      at Script1.run(Script1.groovy:108)
       

          [JENKINS-53143] EnvInject converts all exception types into EnvInjectException

          Dana Goyette added a comment -

          Another noteworthy exception type it eats: org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException

          Dana Goyette added a comment - Another noteworthy exception type it eats: org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException

          Oleg Nenashev added a comment -

          AbortException can be propagated directly in the referenced code, I will accept the pull request if you propose it.

          RejectedAccessException is a bit more tricky, because the API cannot be easily extended in a compatible way. What's wrong with wrapping it by a EnvInjectException from your PoV? The cause can be still analyzed from UI / code if needed 

          Oleg Nenashev added a comment - AbortException can be propagated directly in the referenced code, I will accept the pull request if you propose it. RejectedAccessException is a bit more tricky, because the API cannot be easily extended in a compatible way. What's wrong with wrapping it by a EnvInjectException from your PoV? The cause can be still analyzed from UI / code if needed 

          Dana Goyette added a comment -

          Oddly, if I deliberately trigger the following "must return a map" code, the AbortException raised there seems to mark the run as Failed, not Aborted.  Perhaps the API  always considers exceptions in wrappers to be failures?  If so, then there's really nothing the plugin can do about it.

          The RejectedAccessException is mostly just about getting a convenient link to the /scriptApproval page, as I seem to recall seeing for RejectedAccessException in other places such as in GroovyPostBuild scripts.

          Dana Goyette added a comment - Oddly, if I deliberately trigger the following "must return a map" code, the AbortException raised there seems to mark the run as Failed, not Aborted.  Perhaps the API  always considers exceptions in wrappers to be failures?  If so, then there's really nothing the plugin can do about it. The RejectedAccessException is mostly just about getting a convenient link to the /scriptApproval page, as I seem to recall seeing for RejectedAccessException in other places such as in GroovyPostBuild scripts.

            Unassigned Unassigned
            danagoyette Dana Goyette
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: