The various {{ScmNavigator}}s in the Bitbucket Branch Source and GitHub Branch source plugins have deprecated their previous APIs in favor or using Traits.

      The generated DSLs do not currently support these trait types by looking at http://localhost:8080/plugin/job-dsl/api-viewer/index.html#path/organizationFolder-organizations-bitbucket. See https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/e220b43404aca15574c7a9be3724a40587093414/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMNavigator.java#L230-L232 for the setter that is annotated with @DataBoundSetter.

          [JENKINS-45860] Support traits for ScmNavigators

          Tim Downey added a comment -

          Yes, resolving this would be helpful.  I've worked around it for now using the configure{} block, but this isn't ideal.

           One thing that's going to be an issue is the  'serverUrl', but this is probably more of an issue for the Bitbucket Branch Source Plugin.  Basically, serverUrl should refer to a globally configured Bitbucket server, but unfortunately, the globally configured server has a name, and this takes an id.  It's not easy to get them to line up properly when you're not doing this manually inside of the gui.

           

          def generatedJobs = new DslScriptLoader(jobManagement).runScript("""
            organizationFolder('Dashboard Pipelines') {
              description('Builds all of the repositories supporting the Deployment Dashboards')
              displayName('Dashboard Generator')
              organizations {
                bitbucket {
                  // Specify the name of the Bitbucket Team or Bitbucket User Account.
                  repoOwner('${repoOwner}')
                  // Credentials used to scan branches and check out sources
                  credentialsId('folder_bitbucketuser')
                  // Left blank to use Bitbucket Cloud -- This should be the id of a globally configured server
                  //serverUrl('Bitbucket')
                  bitbucketServerUrl('${serverUrl}')
                }      
              }
          
              // We need to configure this stuff by hand until JobDSL gets some support
              configure { node ->
                  def traits = node / navigators / 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMNavigator' / traits
                  traits << 'jenkins.scm.impl.trait.RegexSCMSourceFilterTrait' {
                      regex('${repoRegex}')   
                  }
                  traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
                      strategyId('1')   
                  }
                  traits << 'jenkins.scm.impl.trait.RegexSCMHeadFilterTrait' {
                      regex('${branchRegex}')   
                  }
              }    
          
              properties {
                folderCredentialsProperty {
                   domainCredentials {
                    domainCredentials {
                        domain {
                          name('GLOBAL')
                          description('Globally available')
                        }
                        credentials {
                          usernamePasswordCredentialsImpl {
                            scope('GLOBAL')
                            id('folder_bitbucketuser')
                            description('Bitbucket User credentials stored at the folder level.')
                            username('${bbUser}')
                            password('${bbPassword}')
                          }
                        }
                    }
                   }
                }
              }
              
            }
          """)
          

           

          Tim Downey added a comment - Yes, resolving this would be helpful.  I've worked around it for now using the configure{} block, but this isn't ideal.  One thing that's going to be an issue is the  'serverUrl', but this is probably more of an issue for the Bitbucket Branch Source Plugin.  Basically, serverUrl should refer to a globally configured Bitbucket server, but unfortunately, the globally configured server has a name, and this takes an id.  It's not easy to get them to line up properly when you're not doing this manually inside of the gui.   def generatedJobs = new DslScriptLoader(jobManagement).runScript(""" organizationFolder( 'Dashboard Pipelines' ) { description( 'Builds all of the repositories supporting the Deployment Dashboards' ) displayName( 'Dashboard Generator' ) organizations { bitbucket { // Specify the name of the Bitbucket Team or Bitbucket User Account. repoOwner( '${repoOwner}' ) // Credentials used to scan branches and check out sources credentialsId( 'folder_bitbucketuser' ) // Left blank to use Bitbucket Cloud -- This should be the id of a globally configured server //serverUrl( 'Bitbucket' ) bitbucketServerUrl( '${serverUrl}' ) } } // We need to configure this stuff by hand until JobDSL gets some support configure { node -> def traits = node / navigators / 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMNavigator' / traits traits << 'jenkins.scm.impl.trait.RegexSCMSourceFilterTrait' { regex( '${repoRegex}' ) } traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' { strategyId( '1' ) } traits << 'jenkins.scm.impl.trait.RegexSCMHeadFilterTrait' { regex( '${branchRegex}' ) } } properties { folderCredentialsProperty { domainCredentials { domainCredentials { domain { name( 'GLOBAL' ) description( 'Globally available' ) } credentials { usernamePasswordCredentialsImpl { scope( 'GLOBAL' ) id( 'folder_bitbucketuser' ) description( 'Bitbucket User credentials stored at the folder level.' ) username( '${bbUser}' ) password( '${bbPassword}' ) } } } } } } } """)  

          The Automatically Generated DSL does not show traits because the structs plugin does not handle wildcards well in generic type declarations. See JENKINS-26535.

          To reproduce this, run the following script in Script Console:

          import org.jenkinsci.plugins.structs.describable.DescribableModel
          import org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator
          
          new DescribableModel(GitHubSCMNavigator)
          

          The output is:

          Result: GitHubSCMNavigator(repoOwner: String, apiUri?: String, buildForkPRHead?(deprecated): boolean, buildForkPRMerge?(deprecated): boolean, buildOriginBranch?(deprecated): boolean, buildOriginBranchWithPR?(deprecated): boolean, buildOriginPRHead?(deprecated): boolean, buildOriginPRMerge?(deprecated): boolean, credentialsId?: String, excludes?(deprecated): String, includes?(deprecated): String, pattern?(deprecated): String, scanCredentialsId?(deprecated): String, traits?: java.lang.UnsupportedOperationException: do not know how to categorize attributes of type jenkins.scm.api.trait.SCMTrait<? extends jenkins.scm.api.trait.SCMTrait<?>>[])
          

          Daniel Spilker added a comment - The Automatically Generated DSL does not show traits because the structs plugin does not handle wildcards well in generic type declarations. See JENKINS-26535 . To reproduce this, run the following script in Script Console: import org.jenkinsci.plugins.structs.describable.DescribableModel import org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator new DescribableModel(GitHubSCMNavigator) The output is: Result: GitHubSCMNavigator(repoOwner: String , apiUri?: String , buildForkPRHead?(deprecated): boolean , buildForkPRMerge?(deprecated): boolean , buildOriginBranch?(deprecated): boolean , buildOriginBranchWithPR?(deprecated): boolean , buildOriginPRHead?(deprecated): boolean , buildOriginPRMerge?(deprecated): boolean , credentialsId?: String , excludes?(deprecated): String , includes?(deprecated): String , pattern?(deprecated): String , scanCredentialsId?(deprecated): String , traits?: java.lang.UnsupportedOperationException: do not know how to categorize attributes of type jenkins.scm.api.trait.SCMTrait<? extends jenkins.scm.api.trait.SCMTrait<?>>[])

          stephenconnolly why is this "Fixed"? The problem still persists.

          Daniel Spilker added a comment - stephenconnolly why is this "Fixed"? The problem still persists.

          Daniel Spilker added a comment - - edited

          Daniel Spilker added a comment - - edited PRs with a workaround for JENKINS-26535 : https://github.com/jenkinsci/github-branch-source-plugin/pull/174 https://github.com/jenkinsci/bitbucket-branch-source-plugin/pull/104

          Code changed in jenkins
          User: Daniel Spilker
          Path:
          src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java
          src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest.java
          http://jenkins-ci.org/commit/github-branch-source-plugin/745dfbfe4f8002b085386e8da8a9416a964472d2
          Log:
          added a workaround for JENKINS-26535

          [FIXES JENKINS-45860]

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Spilker Path: src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest.java http://jenkins-ci.org/commit/github-branch-source-plugin/745dfbfe4f8002b085386e8da8a9416a964472d2 Log: added a workaround for JENKINS-26535 [FIXES JENKINS-45860]

          Code changed in jenkins
          User: Robert Sandell
          Path:
          src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java
          src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest.java
          http://jenkins-ci.org/commit/github-branch-source-plugin/2aaa13771c05c784bfff060856ed6c4d055bf6f1
          Log:
          Merge pull request #174 from daspilker/JENKINS-45860

          JENKINS-45860 added a workaround for JENKINS-26535

          Compare: https://github.com/jenkinsci/github-branch-source-plugin/compare/66373c2859f1...2aaa13771c05

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Robert Sandell Path: src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest.java http://jenkins-ci.org/commit/github-branch-source-plugin/2aaa13771c05c784bfff060856ed6c4d055bf6f1 Log: Merge pull request #174 from daspilker/ JENKINS-45860 JENKINS-45860 added a workaround for JENKINS-26535 Compare: https://github.com/jenkinsci/github-branch-source-plugin/compare/66373c2859f1...2aaa13771c05

          René Scheibe added a comment - - edited daspilker do you think it's also feasible to filter the traits shown in the Job DSL API viewer? Maybe using something like getTraitsDescriptorLists here and here . Currently all available traits (I guess SCMTraits) are shown in multiple places, even if not all of them are suitable for the context. For example having installed: https://plugins.jenkins.io/github-branch-source https://plugins.jenkins.io/cloudbees-bitbucket-branch-source https://plugins.jenkins.io/mercurial SCMSource http://localhost:8080/plugin/job-dsl/api-viewer/index.html#method/jenkins.scm.api.SCMSource$$List.github http://localhost:8080/plugin/job-dsl/api-viewer/index.html#method/jenkins.scm.api.SCMSource$$List.Bitbucket http://localhost:8080/plugin/job-dsl/api-viewer/index.html#method/jenkins.scm.api.SCMSource$$List.mercurialSCMSource ScmNavigatorsContext http://localhost:8080/plugin/job-dsl/api-viewer/index.html#method/javaposse.jobdsl.dsl.helpers.workflow.ScmNavigatorsContext.Bitbucket http://localhost:8080/plugin/job-dsl/api-viewer/index.html#method/javaposse.jobdsl.dsl.helpers.workflow.ScmNavigatorsContext.github

            daspilker Daniel Spilker
            mkobit Mike Kobit
            Votes:
            5 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: