Skip to content

Instantly share code, notes, and snippets.

@harlowja
Created August 23, 2016 18:20
Show Gist options
  • Save harlowja/fb8afd1db43cbb56a3453429a3cf5ba0 to your computer and use it in GitHub Desktop.
Save harlowja/fb8afd1db43cbb56a3453429a3cf5ba0 to your computer and use it in GitHub Desktop.
/**
* Build out our work...
*/
def build(String project,
String project_url, String project_branch,
String patches_url, String patch_branch,
String requirement_url, String requirement_branch,
String venv_py_version, String test_path) {
def stashes = [
clean: make_stash_name("${project}-clean-${project_branch}"),
dirty: make_stash_name("${project}-dirty-${project_branch}"),
patches: make_stash_name("${project}-patches-${patch_branch}"),
constraints: make_stash_name("${project}-constraints-${requirement_branch}"),
]
def cloners = [:]
def cloner_name = ["cloner", project, project_branch].join(":")
cloners[cloner_name] = {
// We can run these on any node, so thats why we do not
// really care where it runs...
node {
clean_ws {
// Checkout the repo (and stash it for later usage).
//
// If checkout takes longer than 10 minutes, something is really wrong.
timeout(time: 600, unit: 'SECONDS') {
git(url: project_url,
branch: project_branch, changelog: false, poll: false)
}
detail_git(project)
stash(name: stashes["clean"],
useDefaultExcludes: false, includes: '**/*')
}
}
}
def patch_getters = [:]
def patch_getter_name = ["patch_fetcher", project, patch_branch].join(":")
patch_getters[patch_getter_name] = {
// We can run these on any node, so thats why we do not
// really care where it runs...
node {
clean_ws {
// Checkout the repo (and stash it for later usage).
//
// If checkout takes longer than 10 minutes, something is really wrong.
timeout(time: 600, unit: 'SECONDS') {
git(url: patches_url,
branch: patch_branch, changelog: false, poll: false)
}
// Each project has a directory (if it has patches)
//
// If it does not have any patches then we can just
// create & stash a empty directory...
sh """
if [ ! -d "${project}" ]; then
mkdir -p -v "${project}"
fi
"""
dir(project) {
stash(name: stashes['patches'],
useDefaultExcludes: false,
includes: '**/*')
}
}
}
}
def req_getters = [:]
def req_getter_name = ["req_getter", project, requirement_branch].join(":")
req_getters[req_getter_name] = {
// We can run these on any node, so thats why we do not
// really care where it runs...
node {
clean_ws {
// Checkout the repo (and stash it for later usage).
//
// If checkout takes longer than 10 minutes, something is really wrong.
timeout(time: 600, unit: 'SECONDS') {
git(url: requirement_url,
branch: requirement_branch,
changelog: false, poll: false)
}
stash(name: stashes['constraints'],
useDefaultExcludes: false,
includes: 'upper-constraints.txt')
}
}
}
def testers = [:]
def tester_name = ["tester", project, project_branch].join(":")
testers[tester_name] = make_a_tester(
'build-slave-cent7', stashes['clean'], stashes['constraints'],
venv_py_version, test_path, "Pre-patch results")
def augmenters = [:]
def aug_name = ["augmenter", project, project_branch].join(":")
augmenters[aug_name] = {
node('build-slave-cent7') {
timeout(time: 600, unit: 'SECONDS') {
wrap([$class: 'AnsiColorBuildWrapper']) {
clean_ws {
// Get the code stash!
unstash(stashes['clean'])
// Get the patches stash
dir(".patches") {
unstash(stashes['patches'])
}
sh """
# This is by default on, we do not want it on for this script.
set +x
for patch_path in \$(ls .patches/*.patch); do
echo "Applying patch \${patch_path}:"
cat "\${patch_path}"
git am < "\${patch_path}"
done
"""
// TODO(harlowja): push the patched repo somewhere?
stash(name: stashes['dirty'],
useDefaultExcludes: false, includes: '**/*')
}
}
}
}
}
def post_testers = [:]
def post_tester_name = ["post-tester", project, project_branch].join(":")
post_testers[post_tester_name] = make_a_tester(
'build-slave-cent7', stashes['dirty'], stashes['constraints'],
venv_py_version, test_path, "Post-patch results")
return [cloners: cloners, testers: testers,
augmenters: augmenters, post_testers: post_testers,
patch_getters: patch_getters, req_getters: req_getters]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment