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

Cannot configure ForkPullRequestDiscoveryTrait by using Job DSL dynamic API

    • 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()
      

          [JENKINS-60874] Cannot configure ForkPullRequestDiscoveryTrait by using Job DSL dynamic API

          Robin Smith added a comment -

          Similar issue reported for the Bitbucket Branch source plugin: JENKINS-61119

          Robin Smith added a comment - Similar issue reported for the Bitbucket Branch source plugin: JENKINS-61119

          Adam Gabryś added a comment -

          Hi bitwiseman. Why did you close the ticket? I know symbols were added, but I used the latest version (2.8.3 now) and it doesn't work. This is a bug ticket.

          Adam Gabryś added a comment - Hi bitwiseman . Why did you close the ticket? I know symbols were added, but I used the latest version (2.8.3 now) and it doesn't work. This is a bug ticket.

          Adam Gabryś added a comment -

          I see no answer and the feature doesn't work, so I'll reopen the issue to not confuse other people.

          Adam Gabryś added a comment - I see no answer and the feature doesn't work, so I'll reopen the issue to not confuse other people.

          Donatien added a comment - - edited

          Please, the description of the issue is very clear, so what can be done now ?

          The issue is marked as resolved, but it still can be reproduced on current Jenkins LTS version + latest github-branch-source-plugin, and job-dsl-plugin.

          Any workaround, or syntax to suggest ?

          Donatien added a comment - - edited Please, the description of the issue is very clear, so what can be done now ? The issue is marked as resolved, but it still can be reproduced on current Jenkins LTS version + latest github-branch-source-plugin , and job-dsl-plugin . Any workaround, or syntax to suggest ?

          Adam Gabryś added a comment -

          The workaround is in the description (the configure block). The Job DSL and GitHub Branch Source plugins' maintainers cannot do anything with it because the issue is caused by JENKINS-26535 (created 2015-01-21).

          Adam Gabryś added a comment - The workaround is in the description (the configure block). The Job DSL and GitHub Branch Source plugins' maintainers cannot do anything with it because the issue is caused by JENKINS-26535 (created 2015-01-21).

          Cory Ringdahl added a comment -

          The workaround doesn't work if you're using sandboxes, because the configure block writes XML directly to the file. We're working on automating internal deployments and configuration of multiple Jenkins clusters to various internal dev teams, so security is paramount. With this bug left unfixed, we're asking for more one-off configurations that will be overwritten by config management, or "yet another snowflake script" configuration workarounds that will plague those who have to support this.

          Cory Ringdahl added a comment - The workaround doesn't work if you're using sandboxes, because the configure block writes XML directly to the file. We're working on automating internal deployments and configuration of multiple Jenkins clusters to various internal dev teams, so security is paramount. With this bug left unfixed, we're asking for more one-off configurations that will be overwritten by config management, or "yet another snowflake script" configuration workarounds that will plague those who have to support this.

          Bitbucket branch source applied workaround to reduce generic in the databound constructor : https://github.com/jenkinsci/bitbucket-branch-source-plugin/pull/738

          Could similar changes be performed on the github plugin ?

          Valentin Delaye added a comment - Bitbucket branch source applied workaround to reduce generic in the databound constructor : https://github.com/jenkinsci/bitbucket-branch-source-plugin/pull/738 Could similar changes be performed on the github plugin ?

          Thanks for pointing that out, jonesbusy. I've created a PR on the GitHub Branch Source plugin that does exactly this. https://github.com/jenkinsci/github-branch-source-plugin/pull/752

          Michael Tughan added a comment - Thanks for pointing that out, jonesbusy . I've created a PR on the GitHub Branch Source plugin that does exactly this. https://github.com/jenkinsci/github-branch-source-plugin/pull/752

          Kevin Puetz added a comment -

          PR has merged and been released in https://github.com/jenkinsci/github-branch-source-plugin/releases/tag/1755.vcdb_d136f3b_25, seems to work now

           

                          gitHubForkDiscovery {
                              // merge the pull request with the current branch revision
                              strategyId(1)
                              trust {
                                  gitHubTrustPermissions()
                              }
                          }
          

          So I think this issue could/should be marked resolved now, as of github-branch-source-1755.vcdb_d136f3b_25.
          mtughan, any reason you were keeping it open?

           

          Kevin Puetz added a comment - PR has merged and been released in https://github.com/jenkinsci/github-branch-source-plugin/releases/tag/1755.vcdb_d136f3b_25 , seems to work now                   gitHubForkDiscovery {                     // merge the pull request with the current branch revision                     strategyId(1)                     trust {                         gitHubTrustPermissions()                     }                 } So I think this issue could/should be marked resolved now, as of github-branch-source-1755.vcdb_d136f3b_25. mtughan , any reason you were keeping it open?  

          puetzk, nope, just forgot to mark it as resolved. That's done now.

          Michael Tughan added a comment - puetzk , nope, just forgot to mark it as resolved. That's done now.

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

              Created:
              Updated:
              Resolved: