Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-43290

PollSCM doesn't update the latest hash, so when running "Scan Repository"/"Branch Indexing" it repeats builds

    Details

    • Similar Issues:

      Description

      We use the snippet

      triggers {
          pollSCM('H/5 * * * *')
      }
      

      to poll Github to pick up new changes to the branches.

      This works fine, but when we click on the "Scan Repository Now" button or Jenkins runs "Branch Indexing" at odd hours in the morning, it will pick up a change in the hash of the latest commit, even though that commit has already been picked up and build via the polling.

      It would be amazing if the pollSCM, when picking up a change, updated the stored hash, so we don't get double builds (mostly because it's spinning up our dev stack at 4am; but also because it's annoying when we're trying to pick up a new branch and it builds everything else as well).

      Thanks

        Attachments

          Activity

          Hide
          stephenconnolly Stephen Connolly added a comment -

          You are not supposed to use polling triggers with multibranch

          Show
          stephenconnolly Stephen Connolly added a comment - You are not supposed to use polling triggers with multibranch
          Hide
          joc Jo Carter added a comment -

          Stephen Connolly Why? What are you supposed to use instead?

          Show
          joc Jo Carter added a comment - Stephen Connolly Why? What are you supposed to use instead?
          Hide
          stephenconnolly Stephen Connolly added a comment -

          Sorry wrong window

          Show
          stephenconnolly Stephen Connolly added a comment - Sorry wrong window
          Hide
          stephenconnolly Stephen Connolly added a comment -

          So Multibranch controls the SCM details.

          A multi-branch project will set the SCM of each branch to check out only the explicit revision it has detected.

          Thus when you click "build now" it will just build the exact revision that the multi-branch project set it to last.

          Polling is evil and it causes a lot of work for the SCM server. The multibranch scan/index does the same as polling but for all branches in one operation. If you do polling the "old school" way then a multi-branch project with 400 branches would be driving 400 polling operations against the SCM server and drown it out. Rather you want one scan by the multi-branch project, which will update all the branches with the correct revisions and handle disabling branches that no longer exist (and would consequently give polling errors further drowning out CPU usage)

          The recommendation is to configure web-hook notification from your SCM, which should be delivering events to the SCM API plugin's event subsystem where that will then trigger a targetted verification of the hook event against only the matching branches and trigger an update.

          Finally you would configure the multibranch project to periodically perform a full scan something like daily or weekly (depends on how long you are ok with orphaned branch jobs remaining)

          Polling does not make sense in a multi-branch pipeline (because the revision is pinned to ensure a consistent checkout) so do not use it as it won't work

          Show
          stephenconnolly Stephen Connolly added a comment - So Multibranch controls the SCM details. A multi-branch project will set the SCM of each branch to check out only the explicit revision it has detected. Thus when you click "build now" it will just build the exact revision that the multi-branch project set it to last. Polling is evil  and it causes a lot of work for the SCM server. The multibranch scan/index does the same as polling but for all branches in one operation . If you do polling the "old school" way then a multi-branch project with 400 branches would be driving 400 polling operations against the SCM server and drown it out. Rather you want one scan by the multi-branch project, which will update all the branches with the correct revisions and handle disabling branches that no longer exist (and would consequently give polling errors further drowning out CPU usage) The recommendation is to configure web-hook notification from your SCM, which should be delivering events to the SCM API plugin's event subsystem where that will then trigger a targetted verification of the hook event against only the matching branches and trigger an update. Finally you would configure the multibranch project to periodically perform a full scan something like daily or weekly (depends on how long you are ok with orphaned branch jobs remaining) Polling does not make sense in a multi-branch pipeline (because the revision is pinned to ensure a consistent checkout) so do not use it as it won't work
          Hide
          joc Jo Carter added a comment -

          Cool. Thanks for explaining.

          Is there documentation for this?  We may have issues because of internal DNS, but I'm sure ops can help.

          Thanks

          Show
          joc Jo Carter added a comment - Cool. Thanks for explaining. Is there documentation for this?  We may have issues because of internal DNS, but I'm sure ops can help. Thanks
          Hide
          khobbits Robert Gornall added a comment -

          We have a internal Jenkins box that is not accessible from the internet.  Trying to convince the network team to expose Jenkins out to the world I think is a bit futile, they would just see it as an additional attack surface, a way to try and test AD credentials.

          Given that situation, you think we should set up branch scanning to every 5 minutes?

          Show
          khobbits Robert Gornall added a comment - We have a internal Jenkins box that is not accessible from the internet.  Trying to convince the network team to expose Jenkins out to the world I think is a bit futile, they would just see it as an additional attack surface, a way to try and test AD credentials. Given that situation, you think we should set up branch scanning to every 5 minutes?
          Hide
          stephenconnolly Stephen Connolly added a comment -

          There are alternatives such as using Amazon SNS or ngrok to pick up just the webhook. After that you are waiting for JENKINS-41072

          Show
          stephenconnolly Stephen Connolly added a comment - There are alternatives such as using Amazon SNS or ngrok to pick up just the webhook. After that you are waiting for JENKINS-41072
          Hide
          chaibapchya Chaitanya Bapat added a comment -

          Hey Stephen since https://issues.jenkins-ci.org/browse/JENKINS-41072 hasn't been resolved yet. How else do you suggest can I use AWS Services for communication between Github and Jenkins?

          I have AWS Lambda function that GitHub WebHook points to. I filter Github events and only if specified comment is made on a PR, I want to trigger a build on Jenkins. However, after disabling the <jenkins-server>/github-webhook from Github, Jenkins doesn't discover new PR branches and as a result I have to manually scan the repo everytime for a new PR so as to be able to use the Lambda function to trigger a job (job fails if the branch isn't discovered).

          How else can I use Lambda function to trigger branch discovery on Jenkins? or how else should I solve the problem of triggering build on Jenkins based on AWS Lambda function?

          Show
          chaibapchya Chaitanya Bapat added a comment - Hey Stephen since https://issues.jenkins-ci.org/browse/JENKINS-41072  hasn't been resolved yet. How else do you suggest can I use AWS Services for communication between Github and Jenkins? I have AWS Lambda function that GitHub WebHook points to. I filter Github events and only if specified comment is made on a PR, I want to trigger a build on Jenkins. However, after disabling the <jenkins-server>/github-webhook from Github, Jenkins doesn't discover new PR branches and as a result I have to manually scan the repo everytime for a new PR so as to be able to use the Lambda function to trigger a job (job fails if the branch isn't discovered). How else can I use Lambda function to trigger branch discovery on Jenkins? or how else should I solve the problem of triggering build on Jenkins based on AWS Lambda function?

            People

            • Assignee:
              Unassigned
              Reporter:
              joc Jo Carter
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: