Get SCM Commit ID from SCMTriggerCause

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Get SCM Commit ID from SCMTriggerCause

felipesfaraco
Hello,

When implementing the canRun function in QueueTaskDispatcher, I am able to find what caused the item to be queued using item.getCauses(), then casting to the appropriate cause.

If the cause is an instance of SCMTriggerCause, I was hoping for a way to get to the COMMIT ID that caused this, but instead the short description only tells me "Started by an SCM change". The other methods available don't seem to help with this. In contrast, the UpstreamCause API provides some handy methods to get relevant information.

In the case of a Run, it seems I could grab it from the EnvVars "GIT_COMMIT", but I'm working with Queue.Item / Job, so I wonder what should be the way to go:

- either get EnvVars from a Job/Queue.Item (not sure how to do so), or;

- instantiate an SCMTriggerItem from my Item, then an SCMTrigger and .. ?

Thank you in advance!

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/3f420018-f4ca-4a99-bc6a-f43e99bf893b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Get SCM Commit ID from SCMTriggerCause

Jesse Glick-4
On Wed, Feb 13, 2019 at 8:02 AM <[hidden email]> wrote:
> If the cause is an instance of SCMTriggerCause, I was hoping for a way to get to the COMMIT ID that caused this, but instead the short description only tells me "Started by an SCM change".

Because that is all the information that is actually available at the
time the _cause_ is created: that one or more SCM changes occurred. If
and when the build actually starts, at that point it will check out
the current head, and then you will know what commit it is building.

If you are dealing with a multibranch project, then an
`SCMRevisionAction` should be available in the `Queue.Item`, and this
would normally encode a particular commit that was determined during
indexing or a webhook and which will be specifically checked out by
the build regardless of where the head might have moved by then.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1kqj-vGw-HXM5HZTNz_RbQa25pZcgqk_eyrqRNmC3yQg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.