Hi all ,

I tried writing a groovy script to list builds in queues assigned to offline 
slaves and it gives me list when I execute via script console but not via a 
Jenkins job.

I'm just a beginner in groovy but tried this below code which works fine in the 
script console but fails with below error as a job.

Any help would be appreciated.

import hudson.model.*

 

def queue = Hudson.instance.queue

println "Total Build Queue contains  ${queue.items.length} items"

println("==============================================")

println("\n")

println("\n")

 

def q = Jenkins.instance.queue

String reason;

  int count;

int time_in_ms ;

println("Below build queues are due to Offline slaves")

 

println("==============================================")

println("\n")

println("\n")

q.items.each {

 

  reason = "${it.why}";

  if(reason.contains("offline"))

     {

  println("Task Name: ${it.task.name}:")

  println(" Job is : ${it.task.url}")

  println("Reason for being in Queue: ${it.why}")

  println("==============================================")

       println("\n")

}

     }

 

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

 

Started by user abcd
[EnvInject] - Loading node environment variables.
Building remotely on slave1 in workspace 
c:/jenkins_home/workspace/BuildStuckInQueue
No emails were triggered.
Total Build Queue contains  12 items
==============================================
 
 
 
 
ERROR: Build step failed with exception
groovy.lang.MissingPropertyException: No such property: Jenkins for class: 
Script1
        at 
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
        at 
org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
        at Script1.run(Script1.groovy:9)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:650)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:636)
        at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:98)
        at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
        at 
hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:785)
        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:537)
        at hudson.model.Run.execute(Run.java:1741)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
        at hudson.model.ResourceController.execute(ResourceController.java:98)
        at hudson.model.Executor.run(Executor.java:408)
Build step 'Execute system Groovy script' marked build as failure
Started calculate disk usage of build
 

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/1dc3c90d-5632-4726-9dfc-e58c4cbed4d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to