Всякий раз, когда я пытаюсь использовать базовый API Jenkins из скрипта groovy, я получаю сообщения об ошибках типа: не могу найти символ ИЛИ нет такого свойства.
Например, если я пытаюсь выполнить приведенный ниже код:
Jenkins.instance.getAllItems(AbstractItem.class).each {
println(it.fullName)
};
Я получаю ошибку ниже в журнале консоли Jenkins:
Started by user Malick, Asif
Running as SYSTEM
[EnvInject] - Loading node environment variables.
Building remotely on SOMESERVER123XYZ in workspace D:\Jenkins\workspace\GetUpstreamJob
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:53)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at Script1.run(Script1.groovy:1)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:375)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:312)
at hudson.plugins.groovy.SystemGroovy.run(SystemGroovy.java:95)
at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:59)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
at hudson.model.Build$BuildExecution.build(Build.java:206)
at hudson.model.Build$BuildExecution.doRun(Build.java:163)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1853)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:427)
Build step 'Execute system Groovy script' marked build as failure
Notifying upstream projects of job completion
Finished: FAILURE
И когда я пытаюсь выполнить код ниже, я получаю ошибку:
@GrabResolver(name='jenkins', root='http://repo.jenkins-ci.org/public/')
@Grapes([
@Grab(group='org.jenkins-ci.main', module='jenkins-core', version='2.167')
])
import hudson.model.*
//println this.computers
println Computer.DisplayExecutor.getDisplayName()
Я получаю ошибку ниже:
Started by user Malick, Asif
Running as SYSTEM
[EnvInject] - Loading node environment variables.
Building remotely on SOMESERVER123XYZ in workspace D:\Jenkins\workspace\GetUpstreamJob
ERROR: Build step failed with exception
groovy.lang.MissingMethodException: No signature of method: static hudson.model.Computer$DisplayExecutor.getDisplayName() is applicable for argument types: () values: []
Possible solutions: getDisplayName()
at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1501)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1487)
at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:53)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at Script1.run(Script1.groovy:10)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:375)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:312)
at hudson.plugins.groovy.SystemGroovy.run(SystemGroovy.java:95)
at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:59)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
at hudson.model.Build$BuildExecution.build(Build.java:206)
at hudson.model.Build$BuildExecution.doRun(Build.java:163)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1853)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:427)
Build step 'Execute system Groovy script' marked build as failure
Notifying upstream projects of job completion
Finished: FAILURE
Не уверен, что мне нужно сделать, чтобы запустить их.
Разрешено ли вообще использовать основной API Jenkins из Jenkins?
Любые Руководство в этом отношении высоко ценится.