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

Cannot configure ForkPullRequestDiscoveryTrait by using Job DSL dynamic API

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • None
    • Job DSL: 1.76
      GitHub Branch Source: 2.5.9-SNAPSHOT (commit: 7179854f068f0012b3d1222f6924e8de5d437513)

      GitHub Branch Source plugin has introduced unique symbols (not released yet), so finally we are able to configure traits by using Job DSL dynamic API instead of configure block. Unfortunately, ForkPullRequestDiscoveryTrait (gitHubForkDiscovery) is unavailable. For now the only possible option is to still use configure block:

      branchSources {
          branchSource {
              source {
                  github {
                      apiUri(config.scm.apiUrl)
                      id(config.name)
                      repoOwner(config.scm.organisation)
                      repository(config.scm.repository)
                      repositoryUrl(config.scm.url)
                      configuredByUrl(false)
                      credentialsId(config.scm.credentialsId)
                      traits {
                          gitHubBranchDiscovery {
                              strategyId(3)
                          }
                          gitHubPullRequestDiscovery {
                              strategyId(1)
                          }
                      }
                  }
              }
              buildStrategies {
                  skipInitialBuildOnFirstBranchIndexing()
              }
          }
      }
      configure {
          def traits = it / 'sources' / 'data' / 'jenkins.branch.BranchSource' / 'source' / 'traits'
          traits << 'org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait' {
              strategyId(1)
              trust(class: 'org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustPermission')
          }
      }
      

      List of available traits in Job DSL Dynamic API Vievwer:

      • gitHubAgedRefsTrait
      • gitHubBranchDiscovery
      • gitHubPullRequestDiscovery
      • gitHubSshCheckout
      • gitHubTagDiscovery

      Missing:

      • gitHubForkDiscovery ← missing, but possible to execute

      I tried:
      1)

      gitHubForkDiscovery {
          strategyId(1)
          trust('trustPermission')
      } 
      
      ERROR: (unknown source) No signature of method: javaposse.jobdsl.plugin.structs.DescribableContext.trust() is applicable for argument types: (java.lang.String) values: [trustPermission]
      Possible solutions: getAt(java.lang.String), print(java.io.PrintWriter), use([Ljava.lang.Object;), print(java.lang.Object), wait(), dump()
      

      2)

      gitHubForkDiscovery {
          strategyId(1)
          trust(gitHubTrustPermissions)
      } 
      
      ERROR: (MultibranchJobFactory.groovy, line 89) No such property: gitHubTrustPermissions for class: javaposse.jobdsl.plugin.structs.DescribableContext
      

      3)

      gitHubForkDiscovery {
          strategyId(1)
          trust(gitHubTrustPermissions())
      } 
      
      ERROR: (unknown source) No signature of method: javaposse.jobdsl.plugin.structs.DescribableContext.gitHubTrustPermissions() is applicable for argument types: () values: []
      

      4)

      gitHubForkDiscovery {
          strategyId(1)
          trust {
              gitHubTrustPermissions()
          }
      } 
      
      ERROR: (unknown source) No signature of method: javaposse.jobdsl.plugin.structs.DescribableContext.gitHubTrustPermissions() is applicable for argument types: () values: []
      

      5)

      gitHubForkDiscovery {
          strategyId(1)
          trust(Class.forName('org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustPermission', true, Jenkins.get().pluginManager.uberClassLoader).getDeclaredConstructor().newInstance())
      } 
      
      ERROR: (unknown source) No signature of method: javaposse.jobdsl.plugin.structs.DescribableContext.trust() is applicable for argument types: (org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustPermission) values: [org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustPermission@3a41ed6e]
      Possible solutions: print(java.io.PrintWriter), use([Ljava.lang.Object;), print(java.lang.Object), wait(), dump(), grep()
      

            mtughan Michael Tughan
            agabrys Adam Gabryś
            Votes:
            10 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: