Found the example on the web. Much of the Groovy examples I have seen entailed using the Jenkins Remote API. I want to use the Jenkins API, running the Groovy script inside jenkins.
Haven't found any example how to get the build process. def build = jenkins.build (or whatever the access class/method is) Where is the starting point using the Jenkins API from a groovy script? Getting server instance, manager instance, thread... mandag 23. februar 2015 15.58.43 UTC+1 skrev Rob Mandeville følgende: > > This is definitely a Groovy question, not a Jenkins question. I’d > expect the same thing if you ran it at the command line. But I won’t send > you away empty-handed. > > > > The doc I’ve seen for Thread is: > > http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html (java) > > http://groovy.codehaus.org/groovy-jdk/java/lang/Thread.html (Groovy) > > > > Neither one refers to “executable”. If you’re trying to find out the > executable (likely “java”), I’m not sure how to help you off-hand. Maybe > you can grovel through java.lang.System.properties? > > > > --Rob > > > > *From:* [email protected] <javascript:> [mailto: > [email protected] <javascript:>] *On Behalf Of *Sverre Moe > *Sent:* Monday, February 23, 2015 9:47 AM > *To:* [email protected] <javascript:> > *Subject:* Re: Learning Jenkins Groovy with Jenkins API > > > > Forgot to mention the error message I got while running the Groovy script > in my build process: > > > > Caught: groovy.lang.MissingPropertyException: No such property: executable > for class: java.lang.Thread > > groovy.lang.MissingPropertyException: No such property: executable for class: > java.lang.Thread > > at hudson4234154804113492123.run(hudson4234154804113492123.groovy:10) > > > > > mandag 23. februar 2015 15.15.50 UTC+1 skrev Sverre Moe følgende: > > I am trying to learn Groovy and using it in a Jenkins build script. > > > > So far I have run some simple groovy in the script console to Jenkins. > > http://jenkins:8080/script > > > > Have tried a simple Groovy script for listing all environment variables, > cut'n'paste code from some examples on the web. > > Tried to run the groovy script with: > > Add build step -> Execute groovy script > > > > Using Groovy Postbuild doesn't work. It will not output a single line of > println, neither in parent nor on any axis slave. > > > > I want to access the current build process to get build information and > project/job information. Reading the javadoc for Jenkins API is better > suited for references and not for learning how to interact with Jenkins. > Real example code is hard to find. Much of the example code is also using > the deprecated hudson.model instead of jenkins.model. > > > > Using the Jenkins Script console many of the imports are already > available. I guess this is not the case when using groovy in build scripts? > > I have also tried skimming through the code at > https://svn.jenkins-ci.org/trunk/hudson/plugins/ for examples, but that > is pure Java code and not Groovy. Though I know pure java code could be > used within Groovy. > > > > import hudson.model.* > import jenkins.model.* > > > println("TESTING Groovy") > > > //The current build process: > def thr = Thread.currentThread() > def build = thr?.executable > > > /** > * VARIABLES > */ > def config = new HashMap() > > > def bindings = getBinding() > config.putAll(bindings.getVariables()) > > > def buildMap = build.getBuildVariables() > config.putAll(buildMap) > > > def envVarsMap = build.parent.builds[0].properties.get("envVars") > config.putAll(envVarsMap) > > > println("TESTING Groovy") > config.keySet().each { key -> > println(key + ": " + config.get(key)) > } > > > > > > > > -- > 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] <javascript:>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jenkinsci-users/fa06fafc-9f6f-4cbb-a0cd-bdfca369bd56%40googlegroups.com > > <https://groups.google.com/d/msgid/jenkinsci-users/fa06fafc-9f6f-4cbb-a0cd-bdfca369bd56%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > Click here > <https://www.mailcontrol.com/sr/uVLLfD1VOsPGX2PQPOmvUjg7ce8j6mWJ!Yy0ETNRqrsJu80isZPQahRXe0CU6bqGO+7meZyhI25AlVq5uz6AOA==> > > to report this email as spam. > > ------------------------------ > This e-mail and the information, including any attachments it contains, > are intended to be a confidential communication only to the person or > entity to whom it is addressed and may contain information that is > privileged. If the reader of this message is not the intended recipient, > you are hereby notified that any dissemination, distribution or copying of > this communication is strictly prohibited. If you have received this > communication in error, please immediately notify the sender and destroy > the original message. > > Thank you. > > Please consider the environment before printing this email. > -- 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/afd70625-669b-4092-a17b-aeae58123c55%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
