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

Multibranch pipeline with default Jenkinsfile fails when scanning p4 streams

    Details

    • Similar Issues:

      Description

      When using the p4 plugin and the Pipeline: Multibranch with defaults plugin, scanning a multibranch pipeline with a default Jenkinsfile results in a java.lang.ClassCastException.

      To reproduce, I used the jenkins/jenkins:2.190.3 docker image of Jenkins with p4-plugin (1.10.7) and the Pipeline: Multibranch with defaults plugin (2.1), as well as a clean docker instance of Perforce (https://github.com/p4paul/helix-docker). I created a stream depot with a couple of dummy streams to use for tests.

      I created a new multibranch pipeline, set up the Branch source to be the p4 depot with the dummy streams, and set the Build configuration to use by default Jenkinsfile.

      It results in the following output:

      Started by user admin
      [Thu Nov 28 16:40:12 UTC 2019] Starting branch indexing...
      ... p4 streams //testDepot/... +ERROR: [Thu Nov 28 16:40:12 UTC 2019] Could not fetch branches from source f9f7c9b6-5fe3-4b7b-bec1-b56ed976ef85
      java.lang.ClassCastException: org.jenkinsci.plugins.pipeline.multibranch.defaults.PipelineBranchDefaultsProjectFactory cannot be cast to org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory
      	at org.jenkinsci.plugins.p4.scm.AbstractP4ScmSource.getLastScan(AbstractP4ScmSource.java:383)
      	at org.jenkinsci.plugins.p4.scm.AbstractP4ScmSource.getRevision(AbstractP4ScmSource.java:310)
      	at org.jenkinsci.plugins.p4.scm.AbstractP4ScmSource.retrieve(AbstractP4ScmSource.java:158)
      Caused: java.io.IOException
      	at org.jenkinsci.plugins.p4.scm.AbstractP4ScmSource.retrieve(AbstractP4ScmSource.java:194)
      	at jenkins.scm.api.SCMSource._retrieve(SCMSource.java:373)
      	at jenkins.scm.api.SCMSource.fetch(SCMSource.java:283)
      	at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:635)
      	at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:277)
      	at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:164)
      	at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:1026)
      	at hudson.model.ResourceController.execute(ResourceController.java:97)
      	at hudson.model.Executor.run(Executor.java:429)
      [Thu Nov 28 16:40:12 UTC 2019] Finished branch indexing. Indexing took 92 ms
      FATAL: Failed to recompute children of testMultibranchDefaults2
      java.io.IOException: java.lang.ClassCastException: org.jenkinsci.plugins.pipeline.multibranch.defaults.PipelineBranchDefaultsProjectFactory cannot be cast to org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory
      	at org.jenkinsci.plugins.p4.scm.AbstractP4ScmSource.retrieve(AbstractP4ScmSource.java:194)
      	at jenkins.scm.api.SCMSource._retrieve(SCMSource.java:373)
      	at jenkins.scm.api.SCMSource.fetch(SCMSource.java:283)
      	at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:635)
      	at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:277)
      	at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:164)
      	at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:1026)
      	at hudson.model.ResourceController.execute(ResourceController.java:97)
      	at hudson.model.Executor.run(Executor.java:429)
      Caused by: java.lang.ClassCastException: org.jenkinsci.plugins.pipeline.multibranch.defaults.PipelineBranchDefaultsProjectFactory cannot be cast to org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory
      	at org.jenkinsci.plugins.p4.scm.AbstractP4ScmSource.getLastScan(AbstractP4ScmSource.java:383)
      	at org.jenkinsci.plugins.p4.scm.AbstractP4ScmSource.getRevision(AbstractP4ScmSource.java:310)
      	at org.jenkinsci.plugins.p4.scm.AbstractP4ScmSource.retrieve(AbstractP4ScmSource.java:158)
      	... 8 more
      Finished: FAILURE
      

      Changing the Build configuration back to by Jenkinsfile, the pipeline scans without error.

        Attachments

          Activity

          Hide
          p4karl Karl Wirth added a comment -

          Hi Matthew Brunton  - Ignore last deleted comment - didn't read the report properly.

          Thanks for highlighting this. I see the same problem.

          When we search for branches we are looking for 'Jenkinsfile' in each branch/stream. If that is not there our detection will fail.  To allow this plugin to work we would need to rewrite the way we do branch detection, so at this time  I don't think we support this plugin.

          I will therefore pass this onto the developers as an enhancement request.

          For developers - from plugin readme https://github.com/jenkinsci/pipeline-multibranch-defaults-plugin/blob/master

          Normally, Jenkins pipelines and Multibranch pipelines requires a developer to save a Jenkinsfile in their repository root on one or more branches. The Pipeline Multibranch Defaults Plugin allows a Jenkins administrator to specify a default Jenkinsfile so that developers do not need to have a Jenkinsfile in their repository.

           

          Show
          p4karl Karl Wirth added a comment - Hi Matthew Brunton   - Ignore last deleted comment - didn't read the report properly. Thanks for highlighting this. I see the same problem. When we search for branches we are looking for 'Jenkinsfile' in each branch/stream. If that is not there our detection will fail.  To allow this plugin to work we would need to rewrite the way we do branch detection, so at this time  I don't think we support this plugin. I will therefore pass this onto the developers as an enhancement request. For developers - from plugin readme https://github.com/jenkinsci/pipeline-multibranch-defaults-plugin/blob/master Normally, Jenkins pipelines and Multibranch pipelines requires a developer to save a Jenkinsfile in their repository root on one or more branches. The Pipeline Multibranch Defaults Plugin allows a Jenkins administrator to specify a default Jenkinsfile so that developers do not need to have a Jenkinsfile in their repository.  
          Hide
          p4paul Paul Allen added a comment -

          Notes (to avoid exception and ignore Multibranch with defaults): 

           - In AbstractP4ScmSource method getLastScan() check instance of branchProject.getProjectFactory()

           - In AbstractP4ScmSource method retrieve() null check revision and continue loop to next P4SCMHead 

          Show
          p4paul Paul Allen added a comment - Notes (to avoid exception and ignore Multibranch with defaults):   - In AbstractP4ScmSource method getLastScan() check instance of branchProject.getProjectFactory()  - In AbstractP4ScmSource method retrieve() null check revision and continue loop to next P4SCMHead 
          Hide
          msmeeth Matthew Smeeth added a comment -

          Fixed, it should now use the default Jenkinsfile when using the Multibranch with defaults plugin.

          Show
          msmeeth Matthew Smeeth added a comment - Fixed, it should now use the default Jenkinsfile when using the Multibranch with defaults plugin.
          Hide
          cbopardikar Charusheela Bopardikar added a comment -

          Released in 1.10.9

          Show
          cbopardikar Charusheela Bopardikar added a comment - Released in 1.10.9

            People

            • Assignee:
              msmeeth Matthew Smeeth
              Reporter:
              mbrunton27 Matthew Brunton
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: