1
votes

I am creating a multibranch pipeline job using the Job DSL Plugin as documented in https://jenkinsci.github.io/job-dsl-plugin/#path/multibranchPipelineJob The multibranch pipeline job is created but it does not create a new pipeline eventhough one branch has a Jenkinsfile. Everytime I trigger a Scan I see the following output:

Getting remote branches...
Seen branch in repository origin/branch1
Seen branch in repository origin/branch2
Seen branch in repository origin/master
Seen 3 remote branches
Checking branch master
Checking branch branch2
Checking branch branch1
Done.
[Tue Jun 20 11:49:46 GMT 2017] Finished branch indexing. Indexing took 2.2 sec
Finished: SUCCESS

If I create a multibranch pipeline via the Jenkins UI and run the job what I see instead is

Getting remote branches...
Seen branch in repository origin/branch1
Seen branch in repository origin/branch2
Seen branch in repository origin/master
Seen 3 remote branches
Checking branch branch2
      ‘Jenkinsfile’ not found
Does not meet criteria
Checking branch branch1
      ‘Jenkinsfile’ found
Met criteria
Done.
[Tue Jun 20 11:52:58 GMT 2017] Finished branch indexing. Indexing took 2.7 sec
Finished: SUCCESS

As you can see ‘Jenkinsfile’ not found is missing when generating the job via the Job DSL Plugin. What I am missing?

My Job DSL Plugin is using the example code as documented:

multibranchPipelineJob('example') {
    branchSources {
        git {
            remote('https://github.com/jenkinsci/job-dsl-plugin.git')
            credentialsId('github-ci')
            includes('JENKINS-*')
        }
    }
    orphanedItemStrategy {
        discardOldItems {
            numToKeep(20)
        }
    }
}
1

1 Answers

1
votes

The example limits the branched being checked to those starting with JENKINS-. Your repository does not contain any branches starting with JENKINS-. Remove the includes call from your Job DSL script:

multibranchPipelineJob('example') {
    branchSources {
        git {
            remote('https://github.com/jenkinsci/job-dsl-plugin.git')
            credentialsId('github-ci')
        }
    }
    orphanedItemStrategy {
        discardOldItems {
            numToKeep(20)
        }
    }
}