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

Support traits for ScmNavigators

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      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.

        Attachments

          Issue Links

            Activity

            Hide
            timdowney 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}')
                            }
                          }
                      }
                     }
                  }
                }
                
              }
            """)
            

             

            Show
            timdowney 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}' ) } } } } } } } """)  
            Hide
            daspilker 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<?>>[])
            
            Show
            daspilker 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<?>>[])
            Hide
            daspilker Daniel Spilker added a comment -

            Stephen Connolly why is this "Fixed"? The problem still persists.

            Show
            daspilker Daniel Spilker added a comment - Stephen Connolly why is this "Fixed"? The problem still persists.
            Show
            daspilker 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
            Hide
            scm_issue_link 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]

            Show
            scm_issue_link 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]
            Hide
            scm_issue_link 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

            Show
            scm_issue_link 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

              People

              • Assignee:
                daspilker Daniel Spilker
                Reporter:
                mkobit Mike Kobit
              • Votes:
                5 Vote for this issue
                Watchers:
                12 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: