Skip to content

Instantly share code, notes, and snippets.

@tamasgal
Created April 27, 2018 11:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tamasgal/e31c59c56a2c6fdb59adf785617f18c7 to your computer and use it in GitHub Desktop.
Save tamasgal/e31c59c56a2c6fdb59adf785617f18c7 to your computer and use it in GitHub Desktop.
Jenkinsfile for parallel Docker images (Python)
#!groovy
def docker_images = ["python:3.5.5", "python:3.6.4", "python:3.6.5"]
def get_stages(docker_image) {
stages = {
docker.image(docker_image).inside {
// If I use this variable as the Virtual Env Folder,
// I get "permission denied" messages from pip, since it tries
// to install into /usr/local/... instead of the pyenv folder!
// def PYTHON_VENV = docker_image.replaceAll('[:.]', '') + 'venv'
// This is the name of the folder where the Virtual Env is created
// However, this is shared between docker images and is not isolated!
def PYTHON_VENV = 'venv'
stage("${docker_image}") {
echo "Running in ${docker_image}"
}
stage("Prepare") {
sh "rm -rf ${PYTHON_VENV}"
sh "python -m venv ${PYTHON_VENV}"
sh """
. ${PYTHON_VENV}/bin/activate
pip install -U pip setuptools wheel
"""
}
stage("Build") {
sh """
. ${PYTHON_VENV}/bin/activate
make
"""
}
stage("Install Dependencies") {
sh """
. ${PYTHON_VENV}/bin/activate
make dependencies
"""
}
stage('Test') {
sh """
. ${PYTHON_VENV}/bin/activate
make clean
make test
"""
junit 'junit.xml'
}
stage("Install") {
sh """
. ${PYTHON_VENV}/bin/activate
make install
"""
}
stage('Docs') {
sh """
. ${PYTHON_VENV}/bin/activate
make doc-dependencies
cd docs
export MPLBACKEND="agg"
make html
"""
}
}
}
return stages
}
node('master') {
checkout scm
def stages = [:]
for (int i = 0; i < docker_images.size(); i++) {
def docker_image = docker_images[i]
stages[docker_image] = get_stages(docker_image)
}
parallel stages
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment