Skip to content

Instantly share code, notes, and snippets.

@abdennour
Created June 16, 2020 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdennour/860e97ec4d5ceae23ff0e2d52384b8bc to your computer and use it in GitHub Desktop.
Save abdennour/860e97ec4d5ceae23ff0e2d52384b8bc to your computer and use it in GitHub Desktop.
Seed Job for Declarative Pipelines with Bitbucket
projects:
- name: PROJA
owner: myteam
repositories:
- name: kito
- name: bito
- name: IDEAS
owner: myteam
repositories:
- name: ideas
- name: barta
import hudson.FilePath
import com.comany.jenkinsconfig.ConfigurationFactory
import javaposse.jobdsl.dsl.DslFactory
createMultibranchJobs()
void createMultibranchJobs() {
DslFactory dsl = this
def cwd = hudson.model.Executor.currentExecutor().getCurrentWorkspace().absolutize()
def configFiles = new FilePath(cwd, 'resources').list('*.yaml')
configFiles.each {
def factory = new ConfigurationFactory(it.read())
configuration = factory.create()
configuration.projects.each { project ->
project.repositories.each { repo ->
folder(project.name) {
}
multibranchPipelineJob("${project.name}/${repo.name}") {
branchSources {
branchSource {
source {
bitbucket {
repoOwner(project.owner)
repository(repo.name)
credentialsId('ae1c49b2-e904-412c-a562-5a55ac68e325')
traits {
cloneOptionTrait {
extension {
shallow (true)
noTags (false)
reference (null)
depth(1)
honorRefspec (false)
timeout (10)
}
}
}
}
}
}
}
orphanedItemStrategy {
discardOldItems {
numToKeep(20)
}
}
// I have to configure it this way because found multiple extensions which provide method BranchDiscoveryTrait
configure {
it / 'sources' / 'data' / 'jenkins.branch.BranchSource' / 'source' / 'traits' / 'com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait' {
strategyId(1)
}
it / 'sources' / 'data' / 'jenkins.branch.BranchSource' / 'source' / 'traits' / 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
strategyId(1)
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment