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

Support traits for ScmNavigators

    XMLWordPrintable

Details

    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

            mkobit Mike Kobit created issue -
            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}')
                            }
                          }
                      }
                     }
                  }
                }
                
              }
            """)
            

             

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

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

            daspilker Daniel Spilker added a comment - stephenconnolly why is this "Fixed"? The problem still persists.
            daspilker Daniel Spilker made changes -
            Link This issue is duplicated by JENKINS-48360 [ JENKINS-48360 ]
            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
            daspilker Daniel Spilker made changes -
            Resolution Fixed [ 1 ]
            Status Resolved [ 5 ] Reopened [ 4 ]
            jglick Jesse Glick made changes -
            Assignee Daniel Spilker [ daspilker ]
            jglick Jesse Glick made changes -
            Status Reopened [ 4 ] Open [ 1 ]
            jglick Jesse Glick made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            jglick Jesse Glick made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]

            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_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]

            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_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
            jglick Jesse Glick made changes -
            Remote Link This issue links to "Page (Jenkins Wiki)" [ 20482 ]
            amuniz Antonio Muñiz made changes -
            Resolution Fixed [ 1 ]
            Status In Review [ 10005 ] Closed [ 6 ]
            amuniz Antonio Muñiz made changes -
            Component/s github-branch-source-plugin [ 20858 ]
            amuniz Antonio Muñiz made changes -
            Component/s bitbucket-branch-source-plugin [ 21428 ]
            Component/s github-branch-source-plugin [ 20858 ]
            amuniz Antonio Muñiz made changes -
            Remote Link This issue links to "Page (Jenkins Wiki)" [ 20503 ]
            renescheibe 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
            bitwiseman Liam Newman made changes -
            Link This issue is related to JENKINS-53912 [ JENKINS-53912 ]

            People

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

              Dates

                Created:
                Updated:
                Resolved: