Last active
February 9, 2019 13:39
-
-
Save fishi0x01/4ac66ebeb096c163b03d46bc1e2ec89b to your computer and use it in GitHub Desktop.
Jenkins JobDSL examples. Code for blog post https://fishi.devtail.io/weblog/2019/02/09/jenkins-as-code-part-3/
This file contains hidden or 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: "serviceA", cron: "@daily"], | |
[name: "serviceB", cron: "@hourly"], | |
[name: "serviceC", cron: "@daily"], | |
] | |
for(project in projects) { | |
folder("${project.name}") | |
multibranchPipelineJob("${project.name}/build") { | |
triggers { | |
cron("${project.cron}") | |
} | |
orphanedItemStrategy { | |
discardOldItems { | |
numToKeep(5) | |
} | |
} | |
branchSources { | |
github { | |
scanCredentialsId('github-ci-user-credentials') | |
repoOwner('devtail') | |
repository("${project.name}") | |
buildOriginBranch(true) | |
buildOriginPRMerge(true) | |
buildOriginBranchWithPR(false) | |
id("${project.name}-branch-id") | |
} | |
} | |
factory { | |
workflowBranchProjectFactory { | |
scriptPath('jenkinsfile/build.groovy') | |
} | |
} | |
} | |
} |
This file contains hidden or 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
node('master') { | |
stage('Checkout') { | |
// Clean workspace and checkout shared library repository on the jenkins master | |
cleanWs() | |
checkout scm | |
} | |
stage('Seed') { | |
// seed the jobs | |
jobDsl(targets: 'resources/jobDSL/*.groovy', sandbox: false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment