Created
December 2, 2016 19:07
-
-
Save harlowja/6c403b87249c84b914e3d60dc4d388a8 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") | |
// 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 = "cloud-init" | |
run_details = pretty_format([ | |
"Project": "${project}", | |
"Project git": "${project_url}", | |
"Project ref": "${project_ref}", | |
"Additions git": "${additions_url}", | |
"Additions ref": "${additions_ref}", | |
]) | |
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}", | |
"Job build tag": "${env.BUILD_TAG}", | |
]) | |
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" | |
stage("Loading remote libraries") | |
helpers = fileLoader.fromGit( | |
"lib/helpers", | |
"git@github.secureserver.net:cloudplatform/jenkins-jobs.git", | |
"master") | |
node { | |
helpers.start(start_msg) | |
} | |
stage("Checkout (external)") | |
project_stash = "${project}.stash" | |
helpers.slack_stage( | |
"Checking out (and stashing) repo for ${project}", false) { | |
helpers.clone_and_stash(project_url, project_ref, project_stash) | |
} | |
stage("Checkout (additions)") | |
additions_stash = "${project}-additions.stash" | |
helpers.slack_stage( | |
"Checking out (and stashing) additions repo for ${project}", false) { | |
helpers.clone_and_stash(additions_url, additions_ref, additions_stash) | |
} | |
common_packages = """ | |
RUN yum -y install python-devel | |
RUN yum -y install python-pip | |
RUN yum -y install python-virtualenv | |
RUN yum -y install rpm-build | |
""" | |
docker_files = [:] | |
docker_files["centos:6"] = """ | |
RUN yum -y install \ | |
http://mirror.centos.org/centos-6/6/extras/x86_64/Packages/epel-release-6-8.noarch.rpm | |
RUN yum clean all | |
${common_packages} | |
""" | |
docker_files["centos:7"] = """ | |
RUN yum -y install \ | |
http://mirror.centos.org/centos-7/7/extras/x86_64/Packages/epel-release-7-6.noarch.rpm | |
RUN yum clean all | |
${common_packages} | |
""" | |
for(build in [[py_version:"py26", image:"centos:6"], [py_version:"py27", image:"centos:7"]]) { | |
def image = build.image | |
def py_version = build.py_version | |
helpers.slack_stage("Testing and building ${py_version} using docker image ${image}", true) { | |
node('build-slave-cent7') { | |
helpers.clean_docker_images() | |
helpers.clean_ws() { | |
dir("cloud-init") { | |
unstash(project_stash) | |
} | |
dir("cloud-init-additions") { | |
unstash(additions_stash) | |
} | |
// Docker base images don't come with much, so we have | |
// to install most of the things we want to be installed... | |
def tmp_docker_file = "FROM ${image}" | |
tmp_docker_file += "\n" + docker_files[image] | |
helpers.pretty_write_file("Dockerfile", tmp_docker_file) | |
// Doesn't really matter (tag or name), since this is not | |
// going to be published anywhere anyway... | |
def tmp_tag = helpers.sanitize_docker_tag("${env.BUILD_TAG}") | |
def tmp_img_name = "${project}/${env.JOB_NAME}:${tmp_tag}" | |
def tmp_img = docker.build(tmp_img_name, ".") | |
tmp_img.inside() { | |
sh """ | |
virtualenv .venv | |
source .venv/bin/activate | |
pip install pip setuptools --upgrade | |
""" | |
sh """ | |
source .venv/bin/activate | |
cd cloud-init | |
pip install -r test-requirements.txt -r requirements.txt | |
nosetests --with-xunit -v --xunit-file results.xml | |
""" | |
} | |
} | |
} | |
} | |
} | |
stage("Finished") | |
helpers.finish() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment