Created
November 3, 2016 20:58
-
-
Save harlowja/d01b0814c454199c630ca56f018a11fa to your computer and use it in GitHub Desktop.
This file contains 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
stage("Initiation") | |
def pp_write_file(filename, contents) { | |
// Write a file + show it (to the jenkins log). | |
def char_am = contents.size() | |
def lines = [ | |
"Writing $char_am chars to ${filename}:", | |
contents, | |
] | |
println(lines.join("\n")) | |
writeFile(file:filename, text:contents) | |
} | |
// NOTE(harlowja): some of these are coming in via job parameters (so that | |
// is why you will not find the variables defined anywhere, they are | |
// apparently injected as globals automatically...) | |
project = "glance" | |
def run_details = pretty_format([ | |
"Project": "${project}", | |
"Project git": "${project_url}", | |
"Project ref": "${project_ref}", | |
"Kolla git": "${kolla_project_url}", | |
"Kolla ref": "${kolla_project_ref}", | |
]) | |
def job_details = pretty_format([ | |
"Job name": "${env.JOB_NAME}", | |
"Job build id": "${env.BUILD_ID}", | |
"Job build number": "${env.BUILD_NUMBER}", | |
"Job build url": "${env.BUILD_URL}", | |
]) | |
def start_msg = "" | |
start_msg += "```\n" | |
start_msg += job_details | |
start_msg += "```\n" | |
start_msg += "*Parameters:*\n" | |
start_msg += "```\n" | |
start_msg += run_details | |
start_msg += "```\n" | |
// See: | |
// | |
// http://docs.openstack.org/developer/kolla/image-building.html | |
def kolla_build_conf = """ | |
[${project}-base] | |
type = git | |
location = https://git.openstack.org/openstack/${project} | |
reference = ${project_ref} | |
""" | |
def kolla_template_overrides = """ | |
{% extends parent_template %} | |
""" | |
stage("Loading remote libraries") | |
def helpers = fileLoader.fromGit( | |
"lib/helpers", | |
"git@github.secureserver.net:cloudplatform/jenkins-jobs.git", | |
"master") | |
node { | |
helpers.start(start_msg) | |
} | |
stage("Kolla checkout (external)") | |
kolla_stash = "kolla.stash" | |
kolla_cloner = { | |
helpers.clone_and_stash(kolla_project_url, kolla_project_ref, kolla_stash) | |
} | |
helpers.slack_stage( | |
"Checking out (and stashing) repo for kolla", | |
kolla_cloner) | |
stage("Image building") | |
image_builder = { | |
node('build-slave-cent7') { | |
helpers.clean_ws { | |
unstash(kolla_stash) | |
helpers.named_sh( | |
"Kolla virtualenv creation & population", | |
""" | |
virtualenv .venv | |
source .venv/bin/activate | |
pip install pip setuptools --upgrade | |
pip install . | |
""" | |
) | |
pp_write_file("etc/kolla/kolla-build.conf", kolla_build_conf) | |
pp_write_file("template-overrides.j2", kolla_template_overrides) | |
helpers.named_sh( | |
"Kolla ${project} image building", | |
""" | |
source .venv/bin/activate | |
kolla-build -t source \ | |
--template-override template-overrides.j2 \ | |
${project} | |
""" | |
) | |
} | |
} | |
} | |
helpers.slack_stage( | |
"Building ${project} using kolla checkout", | |
image_builder) | |
stage("Finished") | |
helpers.finish() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment