Skip to content

Instantly share code, notes, and snippets.

@StephenKing
Last active May 14, 2019 09:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save StephenKing/c0949c79a6e91dd03391 to your computer and use it in GitHub Desktop.
Save StephenKing/c0949c79a6e91dd03391 to your computer and use it in GitHub Desktop.
ls3-chef-job-dsl
job("main-repo") {
scm {
github("StephenKing/chef-ci-main-repo")
}
steps {
shell("knife upload roles environments data_bags --chef-repo-path ./")
}
}
def organization = 'lsinfo3'
def userType = 'orgs' // 'orgs' or 'users'
def repoFilter = ~/^chef-/ // regex, http://docs.groovy-lang.org/latest/html/documentation/#_pattern_operator
repoApi = new URL("https://api.github.com/${userType}/${organization}/repos")
repos = new groovy.json.JsonSlurper().parse(repoApi.newReader())
repos.findAll{ r -> r.name =~ repoFilter }.each {
def repoName = it.name
def jobBaseName = repoName.replaceAll('/','-')
def branchName = "master"
job("${jobBaseName}-clone") {
displayName "Cookbook: $repoName ($branchName) CLONE"
scm {
github("${organization}/${repoName}", branchName)
}
triggers() {
githubPush()
pullRequest {
cron('H/5 * * * *')
useGitHubHooks()
permitAll()
}
}
publishers {
// we have to override the default exclude pattern of Ant, as we would otherwise loose all .git* directories and files (JENKINS-13888)
// signature: publishCloneWorkspace(String workspaceGlob, String workspaceExcludeGlob = '',
// String criteria = 'Any', String archiveMethod = 'TAR',
// boolean overrideDefaultExcludes = false,
// Closure cloneWorkspaceClosure = null)
// therefore, we set overrideDefaultExcludes = true
publishCloneWorkspace('*/', '', 'Any', 'TAR', true, null)
downstream("${jobBaseName}-syntax")
aggregateDownstreamTestResults()
}
}
job("${jobBaseName}-syntax") {
displayName "Cookbook: $repoName ($branchName) SYNTAX"
scm {
cloneWorkspace("${jobBaseName}-clone")
}
steps {
shell("knife cookbook test --all --cookbook-path .")
shell("rubocop || true")
shell("foodcritic . -f correctness")
}
publishers {
warnings(['Foodcritic'], [:], {
canRunOnFailed true
})
downstream("${jobBaseName}-version-bump")
}
}
job("${jobBaseName}-version-bump") {
displayName "Cookbook: $repoName ($branchName) VERSION BUMP"
scm {
cloneWorkspace("${jobBaseName}-clone")
}
steps {
shell("/opt/chefdk/embedded/bin/thor version:bump patch")
shell("if [ -f Berksfile.lock ]; then berks update; else berks install; fi")
}
publishers {
publishCloneWorkspace('*/', '', 'Any', 'TAR', true, null)
downstream("${jobBaseName}-upload")
}
}
job("${jobBaseName}-upload") {
displayName "Cookbook: $repoName ($branchName) UPLOAD"
scm {
cloneWorkspace("${jobBaseName}-version-bump")
}
steps {
shell("berks upload --ssl-verify=false")
}
}
buildPipelineView(jobBaseName) {
filterBuildQueue()
filterExecutors()
title("Chef: ${jobBaseName}")
displayedBuilds(5)
selectedJob("${jobBaseName}-clone")
alwaysAllowManualTrigger()
showPipelineParameters()
refreshFrequency(60)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment