ERROR: Found multiple extensions which provide method branchDiscoveryTrait with arguments []: [[com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait, jenkins.plugins.git.traits.BranchDiscoveryTrait, org.jenkinsci.plugins.github_branch_source.

94 views
Skip to first unread message

Eugène Ngontang

unread,
Jun 22, 2021, 10:35:33 AM6/22/21
to job-dsl-plugin
Hi,

I'm using jenkins jobDSL plugin to generate my pipeline jobs from a groovy script, where I'm trying to create a multibranchPipelineJob as you can in the following line

     17 multibranchPipelineJob("projects/${project_name}/${component_name}") {
     18   branchSources {
     19     branchSource {
     20       source {
     21         git {
     22           remote(component.repository)
     23           credentialsId(component.credentials)
     24           traits {
     25             branchDiscoveryTrait()
     26             cleanBeforeCheckoutTrait()
     27           }
     28         }
     29       }
     30       strategy {
     31         defaultBranchPropertyStrategy {
     32           props {
     33           }
     34         }
     35       }
     36     }
     37   }
     38   triggers {
     39     periodic(5)
     40   }
     41   orphanedItemStrategy {
     42     discardOldItems {
     43       // numToKeep(20)
     44     }
     45   }
     46   if (component.jenkinsfile) {
     47     factory {
     48       workflowBranchProjectFactory {
     49         scriptPath(component.jenkinsfile)
     50       }
     51     }
     52   }
     53 }

When the main pipeline job executing this code runs, it raises this (apparently know) error :

> ERROR: Found multiple extensions which provide method
> branchDiscoveryTrait with arguments []:
> [[com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait,
> jenkins.plugins.git.traits.BranchDiscoveryTrait,
> org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait]]

image (1).png

I've searched and see many results where people say that we should add `@Symbol` annotations to the `traits` implementations or to the relevant descriptors.

But I don't understand exactly what to do and where to place that @Symbol, people seem to say it solves the issue, but there is nowhere a good explanation and guidance to apply the fix.

Please what should I do where should the modification be done in the plugin code or elsewhere?

Best regards,
Eugène NG

  

Eugène Ngontang

unread,
Jun 22, 2021, 4:45:29 PM6/22/21
to job-dsl-plugin
Hi,

I solved it by using the specific `git` scm class, and the correct syntax was :

     17 multibranchPipelineJob("projects/${project_name}/${component_name}") {
     18   branchSources {
     19     branchSource {
     20       source {
     21         git {
     22           remote(component.repository)
     23           credentialsId(component.credentials)
     24           traits {
     25             gitBranchDiscovery()
     26             cleanBeforeCheckoutTrait {
     27               extension {
     28                 deleteUntrackedNestedRepositories(false)
     29               }
     30             }
     31           }
     32         }
     33       }
     34       strategy {
     35         defaultBranchPropertyStrategy {
     36           props {
     37           }
     38         }
     39       }
     40     }
     41   }
     42   triggers {
     43     periodic(5)
     44   }
     45   orphanedItemStrategy {
     46     discardOldItems {
     47       // numToKeep(20)
     48     }
     49   }
     50   if (component.jenkinsfile) {
     51     factory {
     52       workflowBranchProjectFactory {
     53         scriptPath(component.jenkinsfile)
     54       }
     55     }
     56   }
     57 }

Regards,
Eugène NG

Reply all
Reply to author
Forward
0 new messages