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.
To reproduce the bug we need to have a Job DSL job that generates the pretest job.
- Set up a git repository for testing. It doesn't matter what the contents are. (But don't create a ready branch yet)
- Create a freestyle job called "SeedJob"
- Add build step "Process Job DSL"
- Use the provided Job DSL script: Copy-paste the script that I have attached to this story.
- In the script, replace instances of _REPOSITORY_ with the URL to your test repository and replace _CREDENTIALS_ with your build users credential ID.
- Run a build on the SeedJob to generate the "Pretest" job. It should be generated next to your seed job.
- Go to the seed job and wait for it to build the initial build (which should fail).
- Create a branch on the test repository named "ready/test".
- 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.
- Delete the first build of the "Pretest" job. (Or delete the entire job and generate it again)
- The newly generated "Pretest" job should now succeed the first build, because the ready branch exists.
- Try creating another ready branch to verify that it does indeed trigger a new build this time.
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.