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

multibranchPipelineJob: add property strategy & script path options

    Details

    • Similar Issues:

      Description

      The job-dsl-plugin does not support the `Branch Sources > Property Strategy` and `Build Configuration > Script Path` options for multi-branch pipeline projects.

      It would useful to be able to specify these in the DSL similar to these examples:

      Apply Default Property Strategy to a Branch Source

      multibranchPipelineJob("my_awesome_job") {
          displayName "my awesome job"
          description "multi-branch pipeline job thingy"
          branchSources {
              git {   
                  remote('https://github.com/jenkinsci/job-dsl-plugin.git')
                  credentialsId('github-ci')
                  includes('JENKINS-*')
                  // set the default property strategy
                  defaultBranchPropertyStrategy {
                      noTriggerBranchProperty()
                  }
              }
          }
      }
      

       

      Apply Named Branch Property Strategy to a Branch Source

      multibranchPipelineJob("my_awesome_job") {
          displayName "my awesome job"
          description "multi-branch pipeline job thingy"
          branchSources {
              git {   
                  remote('https://github.com/jenkinsci/job-dsl-plugin.git')
                  credentialsId('github-ci')
                  includes('JENKINS-*')
                  // set the named branch property strategy
                  namedExceptionsBranchPropertyStrategy {
                      // only trigger branch build for the `master` branch
                      defaultProperties {
                          noTriggerBranchProperty()
                      }
                      namedException {
                          // could include noTriggerBranchProperty() here if there was no default properties
                          branch('master')
                      }
                  }
              }
          }
      }
      

      Set Script Path for the Project Factory

      multibranchPipelineJob("my_awesome_job") {
          displayName "my awesome job"
          description "multi-branch pipeline job thingy"
          branchSources {
              git {   
                  remote('https://github.com/jenkinsci/job-dsl-plugin.git')
                  credentialsId('github-ci')
                  includes('JENKINS-*')
              }
          }
          factory {
              workflowBranchProjectFactory {
          	    scriptPath('pipelines/entryPoint.groovy')
              }
          }
      }
      

        Attachments

          Activity

          Show
          djfdyuruiry matthew snoddy added a comment - PR Submitted: https://github.com/jenkinsci/job-dsl-plugin/pull/1109
          Hide
          daspilker Daniel Spilker added a comment -

          All these options (and many more) are already supported by the Dynamic DSL:

          multibranchPipelineJob('example-1') {
            branchSources {
              branchSource {
                source {
                  git {
                    id('3d9bee85-412a-47ab-b081-541981dde14a')
                    remote('https://github.com/jenkinsci/job-dsl-plugin.git')
                    credentialsId('github-ci')
                  }
                }
                strategy {
                  defaultBranchPropertyStrategy {
                    props {
                      noTriggerBranchProperty()
                    }
                  }
                }
              }
            }
          }
          
          multibranchPipelineJob('example-2') {
            branchSources {
              branchSource {
                source {
                  git {
                    id('3d9bee85-412a-47ab-b081-541981dde14a')
                    remote('https://github.com/jenkinsci/job-dsl-plugin.git')
                    credentialsId('github-ci')
                  }
                }
                strategy {
                  namedExceptionsBranchPropertyStrategy {          
                    defaultProperties {
                      noTriggerBranchProperty()
                    }
                    namedExceptions {
                      named {
                        name('master')
                      }
                    }
                  }
                }
              }
            }
          }
          
          multibranchPipelineJob('example-3') {
            branchSources {
              branchSource {
                source {
                  git {
                    id('3d9bee85-412a-47ab-b081-541981dde14a')
                    remote('https://github.com/jenkinsci/job-dsl-plugin.git')
                    credentialsId('github-ci')
                  }
                }      
              }
            }
            factory {
              workflowMultiBranchProjectFactory {
               scriptPath('pipelines/entryPoint.groovy')
              }
            } 
          }
          
          Show
          daspilker Daniel Spilker added a comment - All these options (and many more) are already supported by the Dynamic DSL : multibranchPipelineJob( 'example-1' ) { branchSources { branchSource { source { git { id( '3d9bee85-412a-47ab-b081-541981dde14a' ) remote( 'https: //github.com/jenkinsci/job-dsl-plugin.git' ) credentialsId( 'github-ci' ) } } strategy { defaultBranchPropertyStrategy { props { noTriggerBranchProperty() } } } } } } multibranchPipelineJob( 'example-2' ) { branchSources { branchSource { source { git { id( '3d9bee85-412a-47ab-b081-541981dde14a' ) remote( 'https: //github.com/jenkinsci/job-dsl-plugin.git' ) credentialsId( 'github-ci' ) } } strategy { namedExceptionsBranchPropertyStrategy { defaultProperties { noTriggerBranchProperty() } namedExceptions { named { name( 'master' ) } } } } } } } multibranchPipelineJob( 'example-3' ) { branchSources { branchSource { source { git { id( '3d9bee85-412a-47ab-b081-541981dde14a' ) remote( 'https: //github.com/jenkinsci/job-dsl-plugin.git' ) credentialsId( 'github-ci' ) } } } } factory { workflowMultiBranchProjectFactory { scriptPath( 'pipelines/entryPoint.groovy' ) } } }
          Hide
          benkeil83 Ben Keil added a comment -

          Do you have an example how to add traits via Dynamic DSL?

          Show
          benkeil83 Ben Keil added a comment - Do you have an example how to add traits via Dynamic DSL?
          Hide
          arichardson Alex Richardson added a comment -

          I tried the suggested approach of

            factory {
              workflowMultiBranchProjectFactory {
               scriptPath('pipelines/entryPoint.groovy')
              }
            } 
          

          However, it doesn't appear to do anything.
          My current workaround is the following:

          Closure addManualXmlOption(String JenkinsfilePath) {
              return {
                  it / 'factory' << 'scriptPath'(JenkinsfilePath)
                  // disable the default github commit status notifier since it's useless (always uses the same context)
                  // and all of the jobs do their own github status notification instead.
                  it / 'sources'/ 'data' / 'jenkins.branch.BranchSource'/ 'source'/ 'traits' << 'com.adobe.jenkins.disable__github__multibranch__status.DisableStatusUpdateTrait'(plugin:'disable-github-multibranch-status@1.1')
              }
          }
          
          multibranchPipelineJob("${i}-TEST-pipeline") {
              branchSources ....
              configure addManualXmlOption('path/to/Jenkinsfile')
          }
          
          Show
          arichardson Alex Richardson added a comment - I tried the suggested approach of factory { workflowMultiBranchProjectFactory { scriptPath( 'pipelines/entryPoint.groovy' ) } } However, it doesn't appear to do anything. My current workaround is the following: Closure addManualXmlOption( String JenkinsfilePath) { return { it / 'factory' << 'scriptPath' (JenkinsfilePath) // disable the default github commit status notifier since it's useless (always uses the same context) // and all of the jobs do their own github status notification instead. it / 'sources' / 'data' / 'jenkins.branch.BranchSource' / 'source' / 'traits' << 'com.adobe.jenkins.disable__github__multibranch__status.DisableStatusUpdateTrait' (plugin: 'disable-github-multibranch-status@1.1' ) } } multibranchPipelineJob( "${i}-TEST-pipeline" ) { branchSources .... configure addManualXmlOption( 'path/to/Jenkinsfile' ) }
          Hide
          jordanjennings Jordan Jennings added a comment -

          Alex Richardson Here's the correct syntax for setting the path: https://stackoverflow.com/a/50775826/1222654

          Show
          jordanjennings Jordan Jennings added a comment - Alex Richardson Here's the correct syntax for setting the path: https://stackoverflow.com/a/50775826/1222654

            People

            • Assignee:
              daspilker Daniel Spilker
              Reporter:
              djfdyuruiry matthew snoddy
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: