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 .. ?
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.