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