-
-
Save prashanth-sams/45aa54ad32a41b9ed52e308836bd338a to your computer and use it in GitHub Desktop.
ls3-chef-job-dsl
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
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