[JIRA] (JENKINS-48960) Org folders repository folder never runs scans on repository

6 views
Skip to first unread message

patrick@tario.org (JIRA)

unread,
Mar 14, 2018, 6:38:02 AM3/14/18
to jenkinsc...@googlegroups.com
Patrick Ruckstuhl commented on Bug JENKINS-48960
 
Re: Org folders repository folder never runs scans on repository

Having the same issue (with bitbucket branch source instead of github).
I also tried to set it through one of the jobs with

pipelineTriggers([[$class: 'PeriodicFolderTrigger', interval: '5m']]),

But didn't work either.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

patrick@tario.org (JIRA)

unread,
Mar 14, 2018, 6:54:03 AM3/14/18
to jenkinsc...@googlegroups.com

Found an easier workaround than to manually edit all the configs.

Using the script console, this will change all the triggers to 5 minutes for the folders inside Organizations

for (f in Jenkins.instance.getAllItems(jenkins.branch.MultiBranchProject.class)) {
  if (f.parent instanceof jenkins.branch.OrganizationFolder) {
	  f.addTrigger(new com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger("5m"));
  }
}

airey.andy+jenkins@gmail.com (JIRA)

unread,
Apr 5, 2018, 5:45:02 AM4/5/18
to jenkinsc...@googlegroups.com

Patrick Ruckstuhl That workaround does not work for me, also using Bitbucket Branch Source plugin.

Is there any progress on solving the core of the issue?
This is kind of blocking.

tmcole93@gmail.com (JIRA)

unread,
Apr 13, 2018, 5:29:04 PM4/13/18
to jenkinsc...@googlegroups.com

Andy Airey I am in the process of setting up a Bitbucket Team Project with the Bitbucket Branch Source plugin and I ran into this issue. I tried Patrick Ruckstuhl's fix and it worked for me. Otherwise, you could access the Jenkins server and edit the multibranch job configs manually (read: via script) and reload configuration from disk.

jimklimov@gmail.com (JIRA)

unread,
Apr 19, 2018, 7:11:02 AM4/19/18
to jenkinsc...@googlegroups.com

Hello all, I posted a similar issue some time ago (now linked it as a duplicate of this one and closed); while waiting for a better solution, I can offer this workaround: to add a job to regularly rescan MBPs that are inside folders : https://pastebin.com/xKM7CStM

It still is sub-optimal and has its quirks, but at least seems to work.

Beware to not set it to too-often, or you could hit Github REST API rate limiting for example.

airey.andy+jenkins@gmail.com (JIRA)

unread,
Apr 23, 2018, 6:01:03 AM4/23/18
to jenkinsc...@googlegroups.com

Tried Patrick Ruckstuhl workaround againd and got it working.

Was trying Jim Klimov's one first but that didn't seem to find any jobs for me.
Also, it requires the GroovyPostBuild plugin or it will not be able to use manager.

airey.andy+jenkins@gmail.com (JIRA)

unread,
Apr 23, 2018, 6:02:02 AM4/23/18
to jenkinsc...@googlegroups.com
Andy Airey edited a comment on Bug JENKINS-48960
Tried [~tario] workaround againd again and got it working this time .

Was trying [~jimklimov]'s one first but that didn't seem to find any jobs for me.
Also, it requires the GroovyPostBuild plugin or it will not be able to use {{manager}}.

cat@rio.team (JIRA)

unread,
Jul 16, 2018, 11:04:02 AM7/16/18
to jenkinsc...@googlegroups.com

Patrick Ruckstuhl solution works. Would be good to be able to alter from UI. Our polling didn't seem to work and I could not figure out why until I noticed the project frequency was not what I expected. 

This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396)

stephen.alan.connolly@gmail.com (JIRA)

unread,
Jul 18, 2018, 7:07:02 AM7/18/18
to jenkinsc...@googlegroups.com

Still waiting for somebody to try

To confirm my analysis you would need to set the Org Folder to a longer period like 2 days or weekly... then you should see the daily scans and then once the org folder scan kicks in, the 24h interval of any one repo's daily scan should end up being delayed by some random amount before resuming the 24h interval again.

So that we can confirm my analysis... with confirmation we can fix...

jamesdh@gmail.com (JIRA)

unread,
Jul 19, 2018, 4:41:03 AM7/19/18
to jenkinsc...@googlegroups.com

Stephen Connolly if it's any help, this is how I recall it initially failing when I reset my Org folder:

  • On a Friday afternoon, recreated the entire Org with a 5 minute scan interval. 
  • On initial scan, all repo's and all branches per repo are correctly scanned. I thought this meant it was fixed at the time. 
  • Monday morning (~2.5 days later) I see that while the org level scans were working, the repo level scans had not, and if I recall correctly, we had activity over that weekend. 

I know this isn't exactly what you're asking for, but it may help until I (or someone else) can setup a test repo with your parameters. We can't afford to make such changes to our active development environment. 

partounian@gmail.com (JIRA)

unread,
Aug 27, 2018, 5:26:03 PM8/27/18
to jenkinsc...@googlegroups.com

Yeah this is still an issue.

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

partounian@gmail.com (JIRA)

unread,
Aug 27, 2018, 5:26:04 PM8/27/18
to jenkinsc...@googlegroups.com
Patrick Artounian edited a comment on Bug JENKINS-48960
Yeah this is still an issue . , basically a blocker for my team

cdunford@alumni.uwo.ca (JIRA)

unread,
Dec 10, 2018, 10:07:03 AM12/10/18
to jenkinsc...@googlegroups.com

This is an issue for me. Patrick's workaround works for me, but is fairly cumbersome. What needs to be done to get this looked at and fixed. It is a fairly highly voted issue.

jamesdh@gmail.com (JIRA)

unread,
Dec 11, 2018, 11:14:08 AM12/11/18
to jenkinsc...@googlegroups.com

If it's any help, I had to setup a fresh Jenkins server for a new project. Again using GitHub Organization plugin to scan a repository for all available branches containing a Jenkinsfile. The repository scan worked the first time as expected, and then immediately started reproducing the original issue as described here. So, pretty easy to setup and reproduce as far as I can tell. 

 

I ended up just creating a job that contains Patrick Ruckstuhl's console script but instead as a pipeline script, so when the scan interval occasionally resets for whatever reason, I could just run the job and it's fixed. A la...

node {
  
for (f in Jenkins.instance.getAllItems(jenkins.branch.MultiBranchProject.class)) {
    if (f.parent instanceof jenkins.branch.OrganizationFolder) {
      f.addTrigger(new com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger("5m"));
    }
  }
}
 
                                                            

Stephen Connolly I'm looking back and trying to understand your original request but not sure it makes sense. Can you break that down with a bit more detail as to just what exactly should be happening? 

jamesdh@gmail.com (JIRA)

unread,
Dec 11, 2018, 11:14:08 AM12/11/18
to jenkinsc...@googlegroups.com
James Hardwick edited a comment on Bug JENKINS-48960
If it's any help, I had to setup a fresh Jenkins server for a new project. Again using GitHub Organization plugin to scan a repository for all available branches containing a Jenkinsfile. The repository scan worked the first time as expected, and then immediately started reproducing the original issue as described here. So, pretty easy to setup and reproduce as far as I can tell. 

 

I ended up just creating a job that contains [~tario]'s console script but instead as a pipeline script, so when the scan interval occasionally resets for whatever reason, I could just run the job and it's fixed. A la...
{code:java}

node {
  for (f in Jenkins.instance.getAllItems(jenkins.branch.MultiBranchProject.class)) {
    if (f.parent instanceof jenkins.branch.OrganizationFolder) {
      f.addTrigger(new com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger("5m"));
    }
  }
}{code}
[~stephenconnolly] I'm looking back and trying to understand your original request but not sure it makes sense. Can you break that down with a bit more detail as to just what exactly *should* be happening? 

stephen.alan.connolly@gmail.com (JIRA)

unread,
Dec 11, 2018, 4:38:03 PM12/11/18
to jenkinsc...@googlegroups.com

There are two periodic scans "configured".

One is user configurable, namely the one at the org folder level. The other is not currently configurable, namely the one at the branch folder level.

Now the way this is designed is on the basis that you will set up webhooks because "polling must die" to quote a blog post from KK ages back. So the periodic scanning is more to cover two cases:

1. To allow controlled pruning of orphaned items. For technical reasons, the code was actually written originally to allow multiple sources in the same org folder. So you could have one source be a github organization and another be a bitbucket team. Then if you moved a repository from the bitbucket team to the github organization the multibranch project would still stay there. This was to mirror the fact that a multibranch project can have multiple sources. However this was too confusing, so we locked the org folders to one source only. In any case, because there originally could be (and for a multibranch project there still can be) multiple things that can claim ownership of a child name, we cannot decide if an event that a name has been deleted by one source will actually result in the deletion of the child. We have to ask all the candidate sources in the priority order: "is this yours?" until we get someone answering "yes"... So the orphaned item strategy only runs with a full scan. This also allows the orphaned item strategy to correctly decide the order in which orphans should be removed.

2. Events may be dropped or lost. We should find those changes eventually. The scan fills that gap.

If you have webhooks set up correctly then you only need scanning say once per day or less frequently.

All the cron triggers store a random offset as a transient field. This random offset is used to decide when in the `H` portion of a trigger rule to actually pick. The periodic folder trigger converts the times into rules like H * * * * (for hourly) or H H * * * (for daily) so this transient field is important that it remain consistent.

What I think is happening is that the org folder scan is resetting the transient field.

So if your org folder is scanning every 5 minutes, you will have a 5 in 60 chance that the transient gets reset to a value in the next 5 minutes. Of course we have two H's for the daily scan that the multibranch has. So basically if my theory that the transient is getting reset is correct then there is a 1 in 288 chance that the transient will have a value resulting in a scan during the next 5 minutes... and then the transient gets reset again. Each 5 minute interval gas a 287 in 288 chance of not scanning... so we are naïvely looking at the probability of a multibranch project not scanning being (287/288)^288 = 0.36... it's actually worse, because that is actually the probability of it checking whether a scan is due... and if the transient field for H is being cleared then so too will this one: https://github.com/jenkinsci/cloudbees-folder-plugin/blob/23367538c5c6b405a3ba63d8033ca459aa2f65a0/src/main/java/com/cloudbees/hudson/plugins/folder/computed/PeriodicFolderTrigger.java#L71 and so if we win the 63% lottery then one of those will run through to initialize lastTriggered to a random value https://github.com/jenkinsci/cloudbees-folder-plugin/blob/23367538c5c6b405a3ba63d8033ca459aa2f65a0/src/main/java/com/cloudbees/hudson/plugins/folder/computed/PeriodicFolderTrigger.java#L211-L217

So if my theory is correct then you would expect:

  • When the org folder is set to scan at a period much shorter than 24h the multibranch will rarely scan.
  • When the org folder is set to scan at a period much longer than 24h the multibranch will scan mostly daily except for the 24h after the org folder scans.

NOTE: the org folder scan is NOT supposed to trigger the child multibranch scans as that would be sympathetic harmonisation and basically result in everything scanning at the same time. The aim is to level out all scanning across the entire period.

NOTE: I would like the child multibranch scanning period to be configurable, but the UI for that was not agreed so I couldn't get approval to work on that in my paid time... and my wife vetoed me working on it in my spare time :shrug:

airey.andy+jenkins@gmail.com (JIRA)

unread,
Dec 12, 2018, 3:34:03 AM12/12/18
to jenkinsc...@googlegroups.com

There's a third case for the need of periodic scanning of underlying multibranch projects; when webhooks don't work (JENKINS-47891).

stephen.alan.connolly@gmail.com (JIRA)

unread,
Dec 12, 2018, 4:23:02 AM12/12/18
to jenkinsc...@googlegroups.com

airey.andy+jenkins@gmail.com (JIRA)

unread,
Dec 12, 2018, 5:28:02 AM12/12/18
to jenkinsc...@googlegroups.com

If it were that simple ...
I guess you did not read the linked issue

jimklimov@gmail.com (JIRA)

unread,
Dec 12, 2018, 5:53:04 AM12/12/18
to jenkinsc...@googlegroups.com

Then there's also a problem of the corporate networks. Our build farm may poll github, but won't be permitted to get webhooks or any other messages initiated from the internet, directly or through tunnels.

Hmm... a case for email-hooks... rss-hooks... out of scope here though.

stephen.alan.connolly@gmail.com (JIRA)

unread,
Dec 12, 2018, 6:27:07 AM12/12/18
to jenkinsc...@googlegroups.com

Jim Klimov so the correct solution to that would be something like the GitHub SNS plugin (if it was updated to replicate events correctly... last time I checked it wasn't )

Andy Airey The point is that those are not issues for the branch-api plugin itself, they are issues with the SCM sources... or the SCMs themselves... or your environment. Polling is exceedingly expensive in terms of overhead to check and also in terms of delay of notification. Especially when you have an entire organization of repositories to scan. For something like GitHub or Bitbucket Cloud, because of API limits, polling may not even be in any way practicable.

If you are really stuck, then there are other paths you can take, for example the Apache Software Foundation uses its own custom org folder and event forwarding... https://github.com/stephenc/asf-gitpubsub-jenkins-plugin (also see the video series where I show how this was developed https://www.youtube.com/watch?v=W8BRtJmq_2Y&list=PLvBBnHmZuNQLXcL6CBZPKbX9OstMNIhTV ... note that the video is real time development of the plugin. The only code I wrote was during the video recordings)

airey.andy+jenkins@gmail.com (JIRA)

unread,
Dec 12, 2018, 7:31:03 AM12/12/18
to jenkinsc...@googlegroups.com

Sure Stephen Connolly, it's just that you were listing a limited set of use-cases. Wanted to share mine as well since you were trying to create the bigger picture here (which is appreciated).

I agree with all your points, I wish already for more than a year now that I could use webhooks, but I simply cannot because it does not exist or is not worked on. (These are good reasons to change CI system btw ...).

I cannot install my own custom plugins on Bitbucket server because I am not in control of that, corporate is and they don't allow us to. They only support the native webhooks.
So yeah, you can argue that this is a problem within my corporate atmosphere - but I am fairly certain there are more businesses out there using Jenkins that are in a similar situation (be it with firewalls or what have you).

I understand that you cannot support each and every environment but it comes down to "polling is dead"  - we all wish it were, but it isn't.

jamesdh@gmail.com (JIRA)

unread,
Dec 12, 2018, 8:39:06 AM12/12/18
to jenkinsc...@googlegroups.com

Yea, we're in the same boat of keeping our Jenkins instance firewall'd off from the outside world, hence the polling. It's not a big deal for us since the Organization being polled has a fairly limited set of repos. 

Every company I've ever been with has used Jenkins this way, and usually has had very legitimate reasons for doing so. I think it'd be a mistake to have a default worldview of "webhooks everywhere". Just my $.02. 

bryce.schober@gmail.com (JIRA)

unread,
Dec 12, 2018, 4:28:03 PM12/12/18
to jenkinsc...@googlegroups.com

Count me as +1 org with a firewalled Jenkins instance that can't currently accept webhooks.

On that point, does the Jenkins community have a guide for best-security-practices forwarding proxy setup for specific webhooks that orgs could follow?

Anthony.Benedetti@gd-ms.ca (JIRA)

unread,
Jun 28, 2019, 1:00:02 PM6/28/19
to jenkinsc...@googlegroups.com

Another +1 org that can't use webhooks.

Any progress here?

kevin.wren@viasat.com (JIRA)

unread,
Jul 22, 2019, 2:41:05 PM7/22/19
to jenkinsc...@googlegroups.com

+1, I also cant use webhooks due to firewalls (and dont have admin access to my jenkins instance). I'm assuming this isnt being worked on after 7 months of low activity?

As anybody found a workaround in in the repo JenkinsFile?

jim.borden@couchbase.com (JIRA)

unread,
Aug 9, 2019, 8:42:03 PM8/9/19
to jenkinsc...@googlegroups.com

Another +1 for firewalls!  Our only remedy to poll and the whole arbitrary 1 day poll on a job quite a ridiculous way to set things up at that.  It took me days to figure out that there were two separate polls going on and left me wondering why I had to constantly click "scan organization now" to get the results I wanted.  

Reply all
Reply to author
Forward
0 new messages