getScm() on AbstractProject vs. Run

91 views
Skip to first unread message

Ullrich Hafner

unread,
Oct 26, 2016, 5:44:33 PM10/26/16
to Jenkins Developers, Lukas Krose
Is there an equivalent method for a Run (e.g. a pipeline job) to get the used SCM?
Method getScm() is available in AbstractProject but not in the parent class Run.

Ulli

Stephen Connolly

unread,
Oct 26, 2016, 6:29:39 PM10/26/16
to jenkin...@googlegroups.com
Well part of the issue is that there can be more than one scm.

I think each scm used attaches a tracking action... most likely associated with the node that the checkout was performed on
--
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 jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/B1B4B44B-AF8F-4269-A907-65D9AE9A9E21%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
Sent from my phone

Ullrich Hafner

unread,
Oct 26, 2016, 6:46:30 PM10/26/16
to Jenkins Developers, Lukas Krose
I see. Would it work if we loop through all these actions? (This implies that we need to know the exact type of these actions, or is there a method to query only SCM actions?) 

What we are trying to achieve:
Compute the warnings in a build and map these warnings to corresponding SCM changes: this enables us to identify new warnings (and the users who committed these new warnings).
 

Slide

unread,
Oct 26, 2016, 6:49:50 PM10/26/16
to Jenkins Developers, Lukas Krose

Stephen Connolly

unread,
Oct 26, 2016, 6:54:55 PM10/26/16
to jenkin...@googlegroups.com
That's the one you want (it does the lookups for you)


On Wednesday 26 October 2016, Slide <slide...@gmail.com> wrote:
On Wed, Oct 26, 2016 at 3:46 PM Ullrich Hafner <ullrich...@gmail.com> wrote:
I see. Would it work if we loop through all these actions? (This implies that we need to know the exact type of these actions, or is there a method to query only SCM actions?) 

What we are trying to achieve:
Compute the warnings in a build and map these warnings to corresponding SCM changes: this enables us to identify new warnings (and the users who committed these new warnings).
Am 27.10.2016 um 00:29 schrieb Stephen Connolly <stephen.alan.connolly@gmail.com>:

Well part of the issue is that there can be more than one scm.

I think each scm used attaches a tracking action... most likely associated with the node that the checkout was performed on

On Wednesday 26 October 2016, Ullrich Hafner <ullrich...@gmail.com> wrote:
Is there an equivalent method for a Run (e.g. a pipeline job) to get the used SCM?
Method getScm() is available in AbstractProject but not in the parent class Run.

Ulli

--
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 jenkinsci-dev+unsubscribe@googlegroups.com.


--
Sent from my phone

--
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 jenkinsci-dev+unsubscribe@googlegroups.com.

--
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 jenkinsci-dev+unsubscribe@googlegroups.com.

--
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 jenkinsci-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAPiUgVdKDwWHOv9aTcmxkOaaHUPZPiv7-_8YJZOgv2Nm4VYV9A%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Jesse Glick

unread,
Oct 26, 2016, 7:18:44 PM10/26/16
to Jenkins Dev
On Wed, Oct 26, 2016 at 6:54 PM, Stephen Connolly
<stephen.al...@gmail.com> wrote:
> That's the one you want (it does the lookups for you)

Do not call that directly. Use
`SCMTriggerItem.asSCMTriggerItem(job).getSCMs()` plus a null check.


Anyway for the stated use case

> Compute the warnings in a build and map these warnings to corresponding SCM changes

`getScm()` was not what you wanted to begin with. You want

Run<?, ?> run = …;
@SuppressWarnings("unchecked") List<ChangeLogSet<? extends
ChangeLogSet.Entry>> changeSets =
run.getClass().getMethod("getChangeSets").invoke(run);

which will work equally well on `AbstractBuild` or `WorkflowRun`. A
core interface to abstract the two is pending.

Ullrich Hafner

unread,
Oct 27, 2016, 8:23:37 AM10/27/16
to Jenkins Developers
>
>> Compute the warnings in a build and map these warnings to corresponding SCM changes
>
> `getScm()` was not what you wanted to begin with. You want
>
> Run<?, ?> run = …;
> @SuppressWarnings("unchecked") List<ChangeLogSet<? extends
> ChangeLogSet.Entry>> changeSets =
> run.getClass().getMethod("getChangeSets").invoke(run);
>
> which will work equally well on `AbstractBuild` or `WorkflowRun`. A
> core interface to abstract the two is pending.
>


I see, this approach is much better, then it should work for each SCM out of the box! Thanks for the hint...

Ullrich Hafner

unread,
Nov 7, 2016, 5:49:18 PM11/7/16
to Jenkins Developers
> Am 27.10.2016 um 01:18 schrieb Jesse Glick <jgl...@cloudbees.com>:
>
> Anyway for the stated use case
>
>> Compute the warnings in a build and map these warnings to corresponding SCM changes
>
> `getScm()` was not what you wanted to begin with. You want
>
> Run<?, ?> run = …;
> @SuppressWarnings("unchecked") List<ChangeLogSet<? extends
> ChangeLogSet.Entry>> changeSets =
> run.getClass().getMethod("getChangeSets").invoke(run);
>

Is there a way to get the diffs or affected line numbers from a ChangeLogSet.Entry? Seems that only the plain path is available.

Jesse Glick

unread,
Nov 7, 2016, 6:57:41 PM11/7/16
to Jenkins Dev
On Mon, Nov 7, 2016 at 5:49 PM, Ullrich Hafner <ullrich...@gmail.com> wrote:
> Is there a way to get the diffs or affected line numbers from a ChangeLogSet.Entry? Seems that only the plain path is available.

Yes, it does not currently define anything more granular than filenames.

Ted Xiao

unread,
Nov 8, 2016, 10:14:43 PM11/8/16
to Jenkins Developers
Any equivalent to Scm.buildEnvVars(AbstractBuild<?,?> build, Map<String, String> env), I wan to inspect scm info (GIT_COMMIT GIT_BRANCH GIT_URL) in RunListener

Jesse Glick

unread,
Nov 9, 2016, 10:00:11 AM11/9/16
to Jenkins Dev
On Tue, Nov 8, 2016 at 10:14 PM, Ted Xiao <xia...@gmail.com> wrote:
> Any equivalent to Scm.buildEnvVars(AbstractBuild<?,?> build, Map<String,
> String> env), I wan to inspect scm info (GIT_COMMIT GIT_BRANCH GIT_URL) in
> RunListener

No equivalent. JENKINS-24141
Reply all
Reply to author
Forward
0 new messages