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

          Mike Kobit created issue -

          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}' ) } } } } } } } """)  
          Steffen Gebert made changes -
          Link New: This issue is related to JENKINS-46202 [ JENKINS-46202 ]

          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<?>>[])
          Daniel Spilker made changes -
          Link New: This issue is blocked by JENKINS-26535 [ JENKINS-26535 ]
          Daniel Spilker made changes -
          Component/s New: github-branch-source-plugin [ 20858 ]
          Component/s New: structs-plugin [ 21442 ]
          Daniel Spilker made changes -
          Assignee Original: Daniel Spilker [ daspilker ]
          Stephen Connolly made changes -
          Link New: This issue duplicates JENKINS-45504 [ JENKINS-45504 ]
          Stephen Connolly made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]

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

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

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

              Created:
              Updated:
              Resolved: