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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/fa06fafc-9f6f-4cbb-a0cd-bdfca369bd56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to