Groovy Question: revision from job?

84 views
Skip to first unread message

Guy Matz

unread,
Dec 9, 2015, 5:40:34 PM12/9/15
to jenkins...@googlegroups.com
Hi!  Anyone know how I can retrieve the git revision from a job?

I can get to the build:

j = Jenkins.instance.getJob('render-master')
b475 = j.getBuildByNumber(475)

but I can't find a way to to get the git revision associated with that build.  Any thoughts would be appreciated!

Thanks a lot,
Guy

Christopher Orr

unread,
Dec 9, 2015, 7:28:23 PM12/9/15
to jenkins...@googlegroups.com
Hi there,
Git metadata is stored in a `BuildData` action, so something like this
(untested) should work:

b475.getAction(hudson.plugins.git.util.BuildData.class).lastBuiltRevision.sha1String

Regards,
Chris

Guy Matz

unread,
Dec 10, 2015, 9:18:28 AM12/10/15
to jenkins...@googlegroups.com
Nicely done!!  How the heck was I supposed to know that!?  :-(  The API is less than intuitive and does not seem to be well documented.  Any advice on how to best use it?

Thanks again!!


--
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 jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/5668C714.30504%40orr.me.uk.
For more options, visit https://groups.google.com/d/optout.

Brian Ray

unread,
Dec 10, 2015, 1:22:53 PM12/10/15
to Jenkins Users
My approach has just been iteratively trying things with the Script Console up in one window and the Javadoc up in other windows. I'm unsure if there is an easier way to learn it.

Christopher Orr

unread,
Dec 10, 2015, 6:00:19 PM12/10/15
to jenkins...@googlegroups.com
Well, I had the advantage of having used that API in my own plugin before :)

But yeah, Git is just plugin like any other, so there's no magical way
of knowing how to access data from its internals.

Though if you know that "Actions" exist, and are a mechanism for plugins
to associate data with a build, you might be able to get somewhere in
general by using the Script Console as Brian mentioned, coupled with a
bit of digging on GitHub.

If you have specific questions, the mailing list or IRC are also good
bets :)

Regards,
Chris
> <mailto:jenkinsci-users%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/5668C714.30504%40orr.me.uk.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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 jenkinsci-use...@googlegroups.com
> <mailto:jenkinsci-use...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/CABnTgtWXk1o10d537DPv37zJe-uFwtnvo9rjZ8E%2BzLkb%3D%2BOitw%40mail.gmail.com
> <https://groups.google.com/d/msgid/jenkinsci-users/CABnTgtWXk1o10d537DPv37zJe-uFwtnvo9rjZ8E%2BzLkb%3D%2BOitw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages