Created
June 16, 2020 03:30
-
-
Save abdennour/860e97ec4d5ceae23ff0e2d52384b8bc to your computer and use it in GitHub Desktop.
Seed Job for Declarative Pipelines with Bitbucket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
projects: | |
- name: PROJA | |
owner: myteam | |
repositories: | |
- name: kito | |
- name: bito | |
- name: IDEAS | |
owner: myteam | |
repositories: | |
- name: ideas | |
- name: barta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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