title: Jenkins - running a working Scriptler script in a job results in NPE
body: <p>I wrote a simple Scriptler script which enables all jobs in a certain view.
  When I execute the script in the Scriplter view, it succeeds.
  However, when I run it as part of a job (Build, Scriptler script) it fails with a NPE. I understand that it does not identify the Jenkins object.</p>
  
  <p>This is the script:</p>
  
  <pre><code>import jenkins.model.Jenkins
  
  Jenkins.instance.getView("VIEW_NAME").items.each { item -&gt;
      println "\nJob: $item.name is enabled"
      item.disabled = false
  }
  </code></pre>
  
  <p>And this is the excpetion:</p>
  
  <pre><code>Execution of script [enableAutomaticTestsViewJobs.groovy] failed - java.lang.NullPointerException: Cannot invoke method getView() on null objectorg.jenkinsci.plugins.scriptler.util.GroovyScript$ScriptlerExecutionException: java.lang.NullPointerException: Cannot invoke method getView() on null object
      at org.jenkinsci.plugins.scriptler.util.GroovyScript.call(GroovyScript.java:131)
      at hudson.remoting.UserRequest.perform(UserRequest.java:121)
      at hudson.remoting.UserRequest.perform(UserRequest.java:49)
      at hudson.remoting.Request$2.run(Request.java:324)
      at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
      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 hudson.remoting.Engine$1$1.run(Engine.java:63)
      at java.lang.Thread.run(Thread.java:745)
      at ......remote call to Channel to /172.23.50.250(Native Method)
      at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1537)
      at hudson.remoting.UserResponse.retrieve(UserRequest.java:253)
      at hudson.remoting.Channel.call(Channel.java:822)
      at org.jenkinsci.plugins.scriptler.builder.ScriptlerBuilder.perform(ScriptlerBuilder.java:116)
      at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
      at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
      at hudson.model.Build$BuildExecution.build(Build.java:205)
      at hudson.model.Build$BuildExecution.doRun(Build.java:162)
      at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
      at hudson.model.Run.execute(Run.java:1728)
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      at hudson.model.ResourceController.execute(ResourceController.java:98)
      at hudson.model.Executor.run(Executor.java:404)
  Caused by: java.lang.NullPointerException: Cannot invoke method getView() on null object
      at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:35)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:57)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
      at Script1.run(Script1.groovy:3)
      at org.jenkinsci.plugins.scriptler.util.GroovyScript.call(GroovyScript.java:122)
      at hudson.remoting.UserRequest.perform(UserRequest.java:121)
      at hudson.remoting.UserRequest.perform(UserRequest.java:49)
      at hudson.remoting.Request$2.run(Request.java:324)
      at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
      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 hudson.remoting.Engine$1$1.run(Engine.java:63)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>Thanks</p>