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

Add @Symbol annotations to traits

    Details

    • Similar Issues:
    • Released As:
      git-plugin 4.0.0, bitbucket-branch-source-plugin 2.7.0, github-branch-source-plugin 2.6.0

      Description

      In order to make using traits easier, we need to add @Symbol annotations to the trait implementations.

        Attachments

          Issue Links

            Activity

            Hide
            stephenconnolly Stephen Connolly added a comment -

            This issue is critically blocked by JENKINS-45503

            If there are two traits with the same @Symbol annotation then the annotation is ignored, thus until the generic discovery traits have been consolidated into SCM-API, we cannot add the @Symbol annotations that we would want to them.

            Ideally we would have

            // in SCM-API plugin
            @Symbol("discoverBranches")
            public class BranchDiscoveryTrait { ... }

            But without JENKINS-45503 we would be forced to implement this as

            // in Git plugin
            @Symbol("discoverGitBranches")
            public class BranchDiscoveryTrait { ... }
            
            // in GitHub Branch Source plugin
            @Symbol("discoverGitHubBranches")
            public class BranchDiscoveryTrait { ... }
            
            // in Bitbucket Branch Source plugin
            @Symbol("discoverBitbucketBranches")
            public class BranchDiscoveryTrait { ... }
            
            // etc

            Furthermore, if we added those annotations, then existing usage would be broken as soon as JENKINS-45503 was implemented unless SCM API had

            // in SCM-API plugin
            @Symbol({"discoverBranches","discoverGitBranches","discoverGitHubBranches","discoverBitbucketBranches"})
            public class BranchDiscoveryTrait { ... }

            Which is effectively encoding SCM specific names into the generic API

             

            Show
            stephenconnolly Stephen Connolly added a comment - This issue is critically blocked by JENKINS-45503 If there are two traits with the same @Symbol annotation then the annotation is ignored, thus until the generic discovery traits have been consolidated into SCM-API, we cannot add the @Symbol annotations that we would want to them. Ideally we would have // in SCM-API plugin @Symbol( "discoverBranches" ) public class BranchDiscoveryTrait { ... } But without JENKINS-45503 we would be forced to implement this as // in Git plugin @Symbol( "discoverGitBranches" ) public class BranchDiscoveryTrait { ... } // in GitHub Branch Source plugin @Symbol( "discoverGitHubBranches" ) public class BranchDiscoveryTrait { ... } // in Bitbucket Branch Source plugin @Symbol( "discoverBitbucketBranches" ) public class BranchDiscoveryTrait { ... } // etc Furthermore, if we added those annotations, then existing usage would be broken as soon as JENKINS-45503 was implemented unless SCM API had // in SCM-API plugin @Symbol({ "discoverBranches" , "discoverGitBranches" , "discoverGitHubBranches" , "discoverBitbucketBranches" }) public class BranchDiscoveryTrait { ... } Which is effectively encoding SCM specific names into the generic API  
            Hide
            jamesdumay James Dumay added a comment -

            Note to self: Stephen Connolly mentioned this was an important future enhancement

            Show
            jamesdumay James Dumay added a comment - Note to self: Stephen Connolly mentioned this was an important future enhancement
            Hide
            nicodeceulaer Nico De Ceulaer added a comment -

             

            After updating our jenkins plugins, we are facing the problem that we cannot set the BranchDiscovery options on a multibranchPipelineJob through job-dsl.

            Googling around I found this issue that seems to explain why we cannot yet use the BranchDiscoveryTrait to fix this.

            Is there an existing workaround to get this behaviour (through a configure block ?)

            Show
            nicodeceulaer Nico De Ceulaer added a comment -   After updating our jenkins plugins, we are facing the problem that we cannot set the BranchDiscovery options on a multibranchPipelineJob through job-dsl. Googling around I found this issue that seems to explain why we cannot yet use the BranchDiscoveryTrait to fix this. Is there an existing workaround to get this behaviour (through a configure block ?)
            Hide
            stephenconnolly Stephen Connolly added a comment -

            I am not familiar enough with the job-dsl plugin to provide an answer Nico De Ceulaer

            Show
            stephenconnolly Stephen Connolly added a comment - I am not familiar enough with the job-dsl plugin to provide an answer Nico De Ceulaer
            Hide
            arty13 Art V added a comment -

            Nico De Ceulaer I don't have much experience with the configure block, but this is what I'm doing for my MultiBranch Job DSL configuration (it's a template I'm using):

            multibranchPipelineJob('${JOB_NAME}') {
                displayName('${JOB_NAME}')
                description('${JOB_DESCRIPTION}')
                orphanedItemStrategy {
                    discardOldItems {
                        numToKeep(7)
                    }
                }
                branchSources {
                    configure { node ->
                        node / sources(class: 'jenkins.branch.MultiBranchProject\$BranchSourceList') / data / 'jenkins.branch.BranchSource' / source(class: 'jenkins.plugins.git.GitSCMSource') {
                            id ''
                            remote '${JOB_GIT_URL}'
                            credentialsId '${GIT_CREDENTIALS_ID}'
                            includes '*'
                            excludes ''
                            ignoreOnPushNotifications 'false'
                            traits {
                                'jenkins.plugins.git.traits.BranchDiscoveryTrait'()
                                'jenkins.plugins.git.traits.WipeWorkspaceTrait'() {
                                    extension(class: 'hudson.plugins.git.extensions.impl.WipeWorkspace')
                                }
                                'jenkins.plugins.git.traits.PreBuildMergeTrait'() {
                                    extension(class: 'hudson.plugins.git.extensions.impl.PreBuildMerge') {
                                        options {
                                            mergeRemote 'origin'
                                            mergeTarget '${GIT_BRANCH}'
                                            mergeStrategy 'default'
                                            fastForwardMode 'FF'
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            

            I hope this helps you further.

            Show
            arty13 Art V added a comment - Nico De Ceulaer I don't have much experience with the configure block, but this is what I'm doing for my MultiBranch Job DSL configuration (it's a template I'm using): multibranchPipelineJob( '${JOB_NAME}' ) { displayName( '${JOB_NAME}' ) description( '${JOB_DESCRIPTION}' ) orphanedItemStrategy { discardOldItems { numToKeep(7) } } branchSources { configure { node -> node / sources(class: 'jenkins.branch.MultiBranchProject\$BranchSourceList' ) / data / 'jenkins.branch.BranchSource' / source(class: 'jenkins.plugins.git.GitSCMSource' ) { id '' remote '${JOB_GIT_URL}' credentialsId '${GIT_CREDENTIALS_ID}' includes '*' excludes '' ignoreOnPushNotifications ' false ' traits { 'jenkins.plugins.git.traits.BranchDiscoveryTrait' () 'jenkins.plugins.git.traits.WipeWorkspaceTrait' () { extension(class: 'hudson.plugins.git.extensions.impl.WipeWorkspace' ) } 'jenkins.plugins.git.traits.PreBuildMergeTrait' () { extension(class: 'hudson.plugins.git.extensions.impl.PreBuildMerge' ) { options { mergeRemote 'origin' mergeTarget '${GIT_BRANCH}' mergeStrategy ' default ' fastForwardMode 'FF' } } } } } } } } I hope this helps you further.
            Hide
            stephenconnolly Stephen Connolly added a comment -

            https://issues.jenkins-ci.org/browse/JENKINS-45860 may have some hints at how to workaround using Job DSL

            Show
            stephenconnolly Stephen Connolly added a comment - https://issues.jenkins-ci.org/browse/JENKINS-45860 may have some hints at how to workaround using Job DSL
            Show
            sag47 Sam Gleske added a comment - I have proposed for the git-plugin https://github.com/jenkinsci/git-plugin/pull/595 I am successfully using the following Job DSL. https://github.com/gimp-ci/jenkins-dsl/blob/2c53863eca8d689f23bd8554a3cd47831bfa7606/jobs/gimp_multibranch_pipelines.groovy#L27-L29
            Hide
            ccaraivan Costin Caraivan added a comment -

            Could this be bumped in priority? These traits are used downstream by the job DSL plugin and their lack forces users to restot to the configure block in the job DSL configurations, which is an unsafe hack, basically.

            Show
            ccaraivan Costin Caraivan added a comment - Could this be bumped in priority? These traits are used downstream by the job DSL plugin and their lack forces users to restot to the configure block in the job DSL configurations, which is an unsafe hack, basically.
            Hide
            markewaite Mark Waite added a comment -

            Included in git plugin 4.0.0 released Nov 2, 2019

            Show
            markewaite Mark Waite added a comment - Included in git plugin 4.0.0 released Nov 2, 2019
            Hide
            sag47 Sam Gleske added a comment -

            Thanks for your work Mark Waite

            Show
            sag47 Sam Gleske added a comment - Thanks for your work Mark Waite
            Hide
            renescheibe René Scheibe added a comment -

            This is not fixed yet, therefore I reopen it.

            There are still the bitbucket-branch-source-plugin and github-branch-source-plugin to be fixed. I opened pull requests for them:

            Show
            renescheibe René Scheibe added a comment - This is not fixed yet, therefore I reopen it. There are still the bitbucket-branch-source-plugin and github-branch-source-plugin to be fixed. I opened pull requests for them: https://github.com/jenkinsci/bitbucket-branch-source-plugin/pull/257 https://github.com/jenkinsci/github-branch-source-plugin/pull/258
            Hide
            markewaite Mark Waite added a comment -

            René Scheibe has this now been resolved since the two pull requests you listed have been merged?

            Show
            markewaite Mark Waite added a comment - René Scheibe has this now been resolved since the two pull requests you listed have been merged?
            Hide
            renescheibe René Scheibe added a comment -

            The former status was correct (fixed but unreleased). I am still waiting for releases of the two plugins. I would then add the version numbers here for reference and close the ticket afterwards.

            Show
            renescheibe René Scheibe added a comment - The former status was correct (fixed but unreleased). I am still waiting for releases of the two plugins. I would then add the version numbers here for reference and close the ticket afterwards.
            Hide
            renescheibe René Scheibe added a comment -

            Now a release for each of the 3 plugins has been performed that contains the relevant changes. Thanks everybody.

            Show
            renescheibe René Scheibe added a comment - Now a release for each of the 3 plugins has been performed that contains the relevant changes. Thanks everybody.
            Hide
            codiophile Erik Blomqvist added a comment -

            I'm really struggling to find documentation on how to use these traits with Job DSL. Can anyone point me in the right direction or is the documentation simply missing? Having to chose a number for the strategy id is anything but self-explanatory. I want to know what the available options are and what they do.

            Show
            codiophile Erik Blomqvist added a comment - I'm really struggling to find documentation on how to use these traits with Job DSL. Can anyone point me in the right direction or is the documentation simply missing? Having to chose a number for the strategy id is anything but self-explanatory. I want to know what the available options are and what they do.
            Hide
            stephenconnolly Stephen Connolly added a comment -

            Erik Blomqvist I recommend using the pipeline snippet generator with the `resolveScm` step as that lets you see the effects on an SCMSource instance.

            See attached video:

            Show
            stephenconnolly Stephen Connolly added a comment - Erik Blomqvist I recommend using the pipeline snippet generator with the `resolveScm` step as that lets you see the effects on an SCMSource instance. See attached video:

              People

              • Assignee:
                Unassigned
                Reporter:
                stephenconnolly Stephen Connolly
              • Votes:
                24 Vote for this issue
                Watchers:
                35 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: