To build and test an application on different versions of Python you need to install them when using a self-hosted agent with Azure Pipelines. Most of everything else you need can be installed with pip. When installed on a self-hosted agent you can use the UsePythonVersion@0 task in your Azure pipeline as you would with a Microsoft hosted agent. Installation is required as UsePythonVersion@0 doesn't support automatic downloading of missing Python versions on self-hosted agents.
This is what I used. So, you might need to adapt.
- Raspberry Pi 4, 8Gb
- Ubuntu server 22.04.3 LTS jammy (arm64). Comes with Python 3.10.12 pre-installed
- Also tested script on ubuntu:jammy Docker image (amd64)
This script will install Python versions in the agent's tool cache according to the requirements explained here. By default this cache is located at _work/_tool in the directory where the agent is installed. The Python versions installed are from the deadsnakes apt repository. After installing from the deadsnakes repository the script installs each Python version using the venv package in the tool cache. The versions installed are 3.8, 3.9, 3.10 and 3.11
- SSH into your agent's host
- cd into it's tool cache.
- Execute the following commands
$ sudo apt-get update $ curl https://raw.githubusercontent.com/p4irin/azp-agent-python-build-tools/main/build-tools.sh > build-tools.sh $ chmod u+x build-tools.sh $ ./build-tools.sh
- Restart your agent. You should be able to run jobs in a matrix using different Python versions.
Tests executed on the Python versions installed by build-tools.sh can be found here. Those tests were run on Raspberry Pis 4 with 8Gb memory.
The script itself, setting op the Python tool cache's directory structure with Python versions, can be tested locally in a Docker container using the image build by the Dockerfile in this repo.
And, the script is tested by the repo's workflow.