• git-plugin 4.0.0, bitbucket-branch-source-plugin 2.7.0, github-branch-source-plugin 2.6.0

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

          [JENKINS-45504] Add @Symbol annotations to traits

          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

           

          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  

          James Dumay added a comment -

          Note to self: stephenconnolly mentioned this was an important future enhancement

          James Dumay added a comment - Note to self: stephenconnolly mentioned this was an important future enhancement

           

          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 ?)

          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 ?)

          I am not familiar enough with the job-dsl plugin to provide an answer nicodeceulaer

          Stephen Connolly added a comment - I am not familiar enough with the job-dsl plugin to provide an answer nicodeceulaer

          Art V added a comment -

          nicodeceulaer 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.

          Art V added a comment - nicodeceulaer 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.

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

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

          Sam Gleske added a comment -

          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

          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.

          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.

          Mark Waite added a comment -

          Included in git plugin 4.0.0 released Nov 2, 2019

          Mark Waite added a comment - Included in git plugin 4.0.0 released Nov 2, 2019

          Sam Gleske added a comment -

          Thanks for your work markewaite

          Sam Gleske added a comment - Thanks for your work markewaite

          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:

          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

          Mark Waite added a comment -

          renescheibe has this now been resolved since the two pull requests you listed have been merged?

          Mark Waite added a comment - renescheibe has this now been resolved since the two pull requests you listed have been merged?

          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.

          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.

          René Scheibe added a comment -

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

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

          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.

          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.

          codiophile 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:

          Stephen Connolly added a comment - codiophile 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:

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

              Created:
              Updated:
              Resolved: