Included and Excluded Regions/Paths in a Multi Branch Pipeline

48 views
Skip to first unread message

Peter Goodman

unread,
May 12, 2019, 9:56:23 AM5/12/19
to Jenkins Developers
Hi,
I'm trying to add an extension which will enable Included and Excluded Regions (paths) for Multi Branch GitHub pipelines. 

I can do this relatively simply using a SCMHeadFilter which works for pull requests because I can get the files changed in the entire pull request. For master though I would really only want to consider those commits since the last build.

How can I figure that out in the SCMHeadFilter.isExcluded(SCMSourceRequest scmSourceRequest, SCMHead scmHead) method? Or is there another way to somehow set this on the underlying GitSCMBuilder when it is being built?

Thanks,
Pete

Robert Sandell

unread,
May 13, 2019, 7:09:41 AM5/13/19
to jenkin...@googlegroups.com
I'm not sure I understand what you are trying to achieve with "Included and Excluded Regions (paths)"?
SCMHeadFilter filters if the supplied SCMHead should be there or not. In your case if you would return false for the master branch it would not create a job for that branch. And if it already had a job it will be marked as dead and removed when the orphaned item strategy kicks in.

/B

--
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/0c5e2277-a35d-4d6c-a342-45cb6d6951c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Robert Sandell
Software Engineer
CloudBees, Inc.
CloudBees-Logo.png
Twitter: robert_sandell

Peter Goodman

unread,
May 13, 2019, 8:20:48 PM5/13/19
to Jenkins Developers
Thanks so much for your reply.

We have a number of mono-repos which have multiple pipelines in them. For any one pipeline I want to only trigger if the files that are changed are beneath certain paths. Imagine many microservices in each repo. Though I'm not here to debate this approach.

I have created an SCMHeadFilter which works well in some scenarios. 
For a pull request I can just cast the SCMHead as "PullRequestSCMHead" and figure out what files were changed in the Pull Request. It's not necessarily checking every commit since the last build but this works pretty well for us.
For the master branch, I really want to check all the commits since the last build on this branch rather than just the current HEAD commit, how could I get that list of commits and perform that check?

The original git plugin seems to have a feature that it calls "included and excluded regions" which seems like it would do the thing that i need but this isn't available in the Multi Branch Git version. https://medium.com/@abhijeetahuja/jenkins-polling-ignores-commits-in-certain-paths-aeb2927b0e7a
I was hoping I could set this by configuring the GitSCMBuilder but the properties are not available.

I also looked at adding a BuildChooser but this gets overwritten in the builder.

I also looked at implementing isRevExcluded in a GitSCMExtension but that gets me to the same place of evaluating a single commit at HEAD rather than the commits since last build.

Pete






On Monday, 13 May 2019 23:09:41 UTC+12, Robert Sandell wrote:
I'm not sure I understand what you are trying to achieve with "Included and Excluded Regions (paths)"?
SCMHeadFilter filters if the supplied SCMHead should be there or not. In your case if you would return false for the master branch it would not create a job for that branch. And if it already had a job it will be marked as dead and removed when the orphaned item strategy kicks in.

/B

Den sön 12 maj 2019 kl 15:56 skrev Peter Goodman <pe...@petegoo.com>:
Hi,
I'm trying to add an extension which will enable Included and Excluded Regions (paths) for Multi Branch GitHub pipelines. 

I can do this relatively simply using a SCMHeadFilter which works for pull requests because I can get the files changed in the entire pull request. For master though I would really only want to consider those commits since the last build.

How can I figure that out in the SCMHeadFilter.isExcluded(SCMSourceRequest scmSourceRequest, SCMHead scmHead) method? Or is there another way to somehow set this on the underlying GitSCMBuilder when it is being built?

Thanks,
Pete

--
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 jenkin...@googlegroups.com.

Robert Sandell

unread,
May 14, 2019, 6:38:56 AM5/14/19
to jenkin...@googlegroups.com

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/d77a17af-2880-43e0-9bc9-f1963b4ed043%40googlegroups.com.

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

Peter Goodman

unread,
May 14, 2019, 4:55:15 PM5/14/19
to Jenkins Developers
Searching for implementations I've found one that was first released 12 days ago


Looks like I can just use this one.

Do you know of a way that I can make a plugin like this configurable from a declarative pipeline?

Robert Sandell

unread,
May 15, 2019, 4:50:05 AM5/15/19
to jenkin...@googlegroups.com
Den tis 14 maj 2019 kl 22:55 skrev Peter Goodman <pe...@petegoo.com>:
Searching for implementations I've found one that was first released 12 days ago


Looks like I can just use this one.

Do you know of a way that I can make a plugin like this configurable from a declarative pipeline?

No, all the multibranch stuff is part of discovering and creating jobs for Jenkinsfiles, so it all runs before any Jenkinsfile. If you want that configuration in source control it's either the Configuration as Code plugin or Job DSL.

 
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/81699146-1420-4e39-a82e-0d2adf5e0c5f%40googlegroups.com.

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

Jesse Glick

unread,
May 29, 2019, 9:14:27 PM5/29/19
to Jenkins Dev
On Sun, May 12, 2019 at 9:56 AM Peter Goodman <pe...@petegoo.com> wrote:
> I'm trying to add an extension which will enable Included and Excluded Regions (paths) for Multi Branch GitHub pipelines.

https://issues.jenkins-ci.org/browse/JENKINS-35988 for the record.
Reply all
Reply to author
Forward
0 new messages