This repo has been adapted from the following Medium article: Basic CI/CD for Python projects with Docker and Jenkins and fixed using the work-around posted in the Medium article: Jenkins+Python 3.6 Alpine Docker Image.
This repo is a reference/guide to the steps needed for getting a successful build on Jenkins with Python 3.
- Follow instructions for downloading Docker on your OS of choice - https://www.docker.com/get-started
- Check Docker is working in the terminal by running
docker -version
- Create a folder with a name of your choice, I chose to create a folder called
./ci-cd-docker-jenkins/
, and added a Dockerfile with the following contents:
Dockerfile
FROM jenkins/jenkins:lts-alpine USER root # Install Python3 here 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 RUN mkdir /my_app WORKDIR /my_app COPY requirements.txt /my_app RUN pwd RUN ls -la
- Build docker image using the following command:
docker build -t “jenkins:test” path/to/repo
In Jenkins build -> execute shell textbox command, enter:
echo 'Start installing dependencies'
#!/bin/bash
pip install -r /my_app/requirements.txt
echo 'Start running test cases'
python -m unittest -v tests/test_hello_world