【问题标题】:Jenkins JobDSL ERROR: Found multiple extensions which provide method branchDiscoveryTrait with arguments []:Jenkins JobDSL 错误:找到了多个扩展,这些扩展为方法 branchDiscoveryTrait 提供了参数 []:
【发布时间】:2021-09-06 03:36:42
【问题描述】:

我正在使用 jenkins jobDSL 插件从 groovy 脚本生成我的管道作业,我正在尝试在以下行中创建一个 multibranchPipelineJob

 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 }

当执行此代码的主管道作业运行时,它会引发此(显然知道)错误:

错误:找到多个提供方法的扩展 带有参数 [] 的 branchDiscoveryTrait: [[com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait, jenkins.plugins.git.traits.BranchDiscoveryTrait, org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait]]

我搜索并看到很多结果,人们说我们应该将 @Symbol 注释添加到 traits 实现或相关描述符中。

但我不明白该做什么以及将 @Symbol 放在哪里,人们似乎说它解决了问题,但没有一个很好的解释和指导来应用修复。

应该在插件代码中还是其他地方进行修改?

【问题讨论】:

    标签: jenkins jenkins-pipeline jenkins-plugins jenkins-groovy jenkins-job-dsl


    【解决方案1】:

    我通过使用特定的git scm 类解决了它,正确的语法是:

     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 }
    

    【讨论】:

    • 对于任何难以理解差异的人,上面的 sn-p 使用 gitBranchDiscovery() 而不是 branchDiscoveryTrait()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-14
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 2021-06-05
    相关资源
    最近更新 更多