Skip to content

Instantly share code, notes, and snippets.

@fishi0x01
Last active February 9, 2019 13:39
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 fishi0x01/4ac66ebeb096c163b03d46bc1e2ec89b to your computer and use it in GitHub Desktop.
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/
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')
}
}
}
}
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