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

Git polling only works if the first build of generated job finds a revision

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: git-plugin, job-dsl-plugin
    • Labels:
      None
    • Environment:
      Jenkins version: 2.251
      Git-plugin version: 4.3.0
    • Similar Issues:

      Description

      Issue description

      We have a CI setup where developers push their changes to a "ready" branch on our repository, which is polled by a Jenkins job - a "pretest" job. The job runs some basic gate-tests on the commits before merging the branch to master. The job polls any branch matching the wildcard: "origin/ready/**".

      Since we have a lot of projects, and sometimes need to work on several baselines at the same time we generate the pretest jobs with the Jenkins Job DSL plugin.

      Now here's the issue: When the pretest job is generated for the first time, a build is always triggered by SCM polling. If a branch exists that matches the "origin/ready/**" pattern, the build succeeds and polling works perfectly as expected from that point on - ready branches created subsequently will trigger builds. BUT if no "ready" branch exists when the job is generated, a build is still triggered but this build fails with the message: "Couldn't find any revision to build. Verify the repository and branch configuration for this job." and then the git polling seems to "get stuck". That means that "ready" branches which are created subsequently does NOT trigger a build - the "Git Polling Log" just reports "No changes". If we delete the initial build from the build log after creating the "ready" branch, the build succeeds and the polling works as expected from this point. So that is our current workaround for the problem.

      Reproducing bug

      To reproduce the bug we need to have a Job DSL job that generates the pretest job.

      1. Set up a git repository for testing. It doesn't matter what the contents are. (But don't create a ready branch yet)
      2. Create a freestyle job called "SeedJob"
        1. Add build step "Process Job DSL"
        2. Use the provided Job DSL script: Copy-paste the script that I have attached to this story.
        3. In the script, replace instances of _REPOSITORY_ with the URL to your test repository and replace _CREDENTIALS_ with your build users credential ID.
      3. Run a build on the SeedJob to generate the "Pretest" job. It should be generated next to your seed job.
      4. Go to the seed job and wait for it to build the initial build (which should fail).
      5. Create a branch on the test repository named "ready/test".
      6. Go back to the seed job and wait for it to poll (or press poll now). The polling log should report "No changes", and no build should be triggered.
      7. Delete the first build of the "Pretest" job. (Or delete the entire job and generate it again)
      8. The newly generated "Pretest" job should now succeed the first build, because the ready branch exists.
      9. Try creating another ready branch to verify that it does indeed trigger a new build this time.

      Update (new workaround)

      We figured out an automatic workaround for the bug. In addition to the ready branch pattern, we added the master branch which always exists in the repository.

      Because of this the first build doesn't fail with "Couldn't find any revision to build. Verify the repository and branch configuration for this job.", because it finds a revision on the master branch. And because it doesn't fail, the polling works as expected from this point.

      We suspect that the job enters a "Never try again" state when it encounters the no revisions error, so that was the idea behind trying to avoid that error.

        Attachments

          Activity

          Hide
          markewaite Mark Waite added a comment -

          Thanks for excellent investigative work and for finding an alternative that meets your needs. That's great and will help other users.

          Show
          markewaite Mark Waite added a comment - Thanks for excellent investigative work and for finding an alternative that meets your needs. That's great and will help other users.

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            kallekro Kalle Kromann
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: