I want to be able to access the first seven characters of the current git
commit SHA-1 hash, from a gant groovy script I run via a build step in my
project (Build With Grails -> Use Grails Wrapper -> Targets = the default
target in the gant script.) I can get that string in the Manage Jenkins ->
Script Console like so:
def job = Hudson.instance.getJob('job-name')
def run = job.getLastBuild()
println run.getEnvironment()["GIT_COMMIT"][0..6]
But I cannot figure out how to replicate that functionality in my gant
script. If I put this into a script, and run it with "Execute system Groovy
script", it works:
import hudson.model.*
def job = Hudson.instance.getJob('job-name')
def run = job.getLastBuild()
println run.getEnvironment()["GIT_COMMIT"][0..6]
But if I phrase it as a gant script, I can't run it as a "system Groovy
script":
groovy.lang.MissingMethodException: No signature of method: Script1.target()
If I run the gant script as a grails target, with this code in place:
import hudson.model.*
target(getGitHash: 'Get the current git commit hash') {
def job = Hudson.instance.getJob('job-name')
def run = job.getLastBuild()
println "current git hash is:"
println run.getEnvironment()["GIT_COMMIT"][0..6]
}
setDefaultTarget(getGitHash)
I get:
No such property: Hudson for class:
How can I get the current git hash from my gant script?
Thanks,
Morgan
--
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].
For more options, visit https://groups.google.com/groups/opt_out.