Jenkins+Python 3.6 Alpine Docker Image

Ehsan Mirsaeedi
2 min readOct 14, 2018

--

Vanilla Jenkins is mostly suitable for Java applications. It was a headache to find away to make Jenkins builds Python 3 bits. Firstly, most of the existing blogs and Q&As assume that you use an installed version of Jenkins. And secondly, they are all mostly written for Python 2 in mind. However, I wanted to use Jenkins Docker image instead of installing it directly into the server and my codes were written in Python 3.

The default official Jenkins image jenkins/jenkins:lts is based on openjdk:8-jdk image, which is itself made from Debian 9 image. Surprisingly, Debian official repository doesn’t contain python3+pip packages. There are in Debian testing repositories though. So, you need to add Debian testing repository to the list of Debian package sources, because it’s not there by default. But sadly, it’s not possible to modify the list of package repositories sources.list to the best of my knowledge. As a result, it’s not possible to extend the default official Jenkins image to create a Python-Supported image from it.

However, there is medication to this madness. There is an alpine image jenkins/jenkins:alpine in Jenkins repository which we can use to create a Dockerfile based on it. As you may know, alpine is the most lightweight linux image out there; it literally misses some of important packages. Therefore, we need to add them to into the Dockerfile to be able to run Python scripts.

FROM jenkins/jenkins:lts-alpine
USER root
RUN apk add — no-cache python3 && \
python3 -m ensurepip && \
pip3 install — upgrade pip setuptools && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
rm -r /root/.cache
RUN apk add pkgconf
RUN apk add build-base
RUN apk add python3-dev

So, you can build this Dockerfile and use the image to run your long waited Python friendly Jenkins.

This Python+Jenkins+Linux mixture was a real mess, especially when compare it to the well documented, clean, and integrated tools we have in Microsoft ecosystem.

--

--