job-dsl: Dynamic DSL - gitscmsource - includes

61 views
Skip to first unread message

Alex

unread,
Jan 20, 2020, 4:42:57 PM1/20/20
to Jenkins Users

pipeline
{
   agent any
   stages {
       stage('test') {
           steps {
               jobDsl scriptText:
                """multibranchPipelineJob("job-features") {
                                    branchSources {
                                        branchSource {
                                                 source {
                                                               git {
                                                                  id('123456789')
                                                                remote("gir-url.git")
                                                                  includes("feature/*")
                                                          }
                                                      }
                                                      strategy {
                                                             defaultBranchPropertyStrategy {
                                                                props {
                                                                        noTriggerBranchProperty()
                                                                      }
                                                              }
                                                      }
                                              }
                   }
                   configure {
                                          def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
                                             traits << 'jenkins.plugins.git.traits.BranchDiscoveryTrait' {}
                                 }
                   triggers {
                       periodic(5)
                   }
                                orphanedItemStrategy {
                       discardOldItems {
                           daysToKeep(3)
                           numToKeep(3)
                       }
                   }
               }"""
           }
       }
   }
}

I am trying to create a job using job-dsl to seed a multibranch job that includes auto discovery of branches and the supress scm strategy. For some reason in this format the includes option is not working. Any ideas?

Alex

unread,
Jan 21, 2020, 6:33:33 AM1/21/20
to Jenkins Users
I fixed it using this:

pipeline {
    agent any
    stages {
        stage('test') {
            steps {
                jobDsl scriptText: 
                """multibranchPipelineJob("multibranch-name") {
    branchSources {
        git {
            id('12312312312')
            remote("gitproject.git")
        }
    }
    configure {

        it / sources / data / 'jenkins.branch.BranchSource' / source / traits << {
            'jenkins.plugins.git.traits.BranchDiscoveryTrait' {}
'jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait' {
                includes('feature/*')
excludes('')
            }
        }

        it / sources / data / 'jenkins.branch.BranchSource' << {

            strategy(class: 'jenkins.branch.DefaultBranchPropertyStrategy') {
                properties(class: 'java.util.Arrays\$ArrayList') {
                    a(class: 'jenkins.branch.BranchProperty-array') {
                        'jenkins.branch.NoTriggerBranchProperty' { }
Reply all
Reply to author
Forward
0 new messages