We're using mercurial as our SCM exclusively, in combination with Jenkins, thanks to this plugin. When Branch Indexing is being run (either triggered or manually), on a multibranch pipeline job, it normally iterates over all the fetched heads to find the Jenkinsfile for each. This is a feature that seems to be added in v 1.58 of the mercurial plugin. However, if one of the branches in the repository does not have a Jenkinsfile, the indexing is terminated with status failed. Exception [ED1EAACEE3A3A53C6B19AA947A23C57976B19FFE-SOMEJOB] $ /usr/bin/hg --config auth.jenkins.prefix=* --config ******** --config ******** --config "auth.jenkins.schemes=http https" locate -r b8b87f2c24b721d475750dfbba88c63bf2bda060 -I path:Jenkinsfile ERROR: Failed to run /usr/bin/hg --config auth.jenkins.prefix=* --config auth.jenkins.username=CLEARTXTUSER --config auth.jenkins.password=CLEARTXTPASS --config "auth.jenkins.schemes=http https" locate -r b8b87f2c24b721d475750dfbba88c63bf2bda060 -I path:Jenkinsfile ERROR: [Thu Feb 23 07:57:10 UTC 2017] Could not fetch branches from source 82b88e38-6997-4253-8e0d-7211e698983b hudson.AbortException at hudson.plugins.mercurial.HgExe.popen(HgExe.java:425) at hudson.plugins.mercurial.MercurialSCMSource$1.stat(MercurialSCMSource.java:150) at org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory$1.isHead(WorkflowBranchProjectFactory.java:52) at hudson.plugins.mercurial.MercurialSCMSource.retrieve(MercurialSCMSource.java:176) at jenkins.scm.api.SCMSource._retrieve(SCMSource.java:300) at jenkins.scm.api.SCMSource.fetch(SCMSource.java:210) at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:628) at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:219) at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:154) at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:967) at hudson.model.ResourceController.execute(ResourceController.java:98) at hudson.model.Executor.run(Executor.java:404) [Thu Feb 23 07:57:10 UTC 2017] Finished branch indexing. Indexing took 5.2 sec FATAL: null Finished: FAILURE How to reproduce This problem can be reproduced consistently using the mercurial plugin v1.58 or 1.59, by:
- Configure a multibranch pipeline job with Mercurial repository, with:
- One or more branches in repo
- At least one branch without Jenkinsfile
- Trigger the 'Scan Multibranch Pipeline' (either manually or on commit)
Likely cause The interaction between Mercurial plugin and Branch API is fairly complex, but my estimation is that the below section of code is throwing an exit code of 1 when no Jenkinsfile is present. This subsequently causes the branch indexing to fail (with exception thrown). https://github.com/jenkinsci/mercurial-plugin/blob/master/src/main/java/hudson/plugins/mercurial/MercurialSCMSource.java#L151 From what I understand of it, the Branch API is designed to throw the exception and stop trying. This would mean that the Mercurial plugin can't pass exit code 1 when a Jenkinsfile is missing. Note that both the methods committed over the last months, 'hg files' and 'hg locate' exit with code 1 if no pattern match is found. Workaround Rollback to Mercurial plugin v1.57 resolved the issue and allows the branch indexing to complete. Of course it removes some of the new and desirable behavior introduced for properly tracking the pipeline enabled branches and marking closed branches. |