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

Add @Symbol annotations to traits

    XMLWordPrintable

    Details

    • Similar Issues:

      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.

              People

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

                Dates

                • Created:
                  Updated: