Jenkins β
Is simple automation tool. Sometimes too simple. It is written in Java.
There is no proper python support, the plugin is either deprecated or abandoned.
Adding python support to Jenkins β
We need β
- Base Jenkins or Jenkins inbound agent image.
- docker or something that replaces docker installed,
- e.g. OrbStack which I personally prefer to have on the local machine.
- Text editor
- Terminal
Docker file β
Yes, we are going to build our image with python π.
In some folder create Dockerfile file. This is a text file called Dockerfile.
Create summat like this:
If we are going to use Jenkins inbound agent (recommended by the developers), then this.
FROM jenkins/inbound-agent:latest
USER root
RUN apt-get update && apt-get upgrade -y && apt-get install -y python3 python3-pip && apt-get install -y rsync
RUN pip install --break-system-packages pytest allure-pytest
USER jenkinsWhat we've just done:
- we've taken the image Jenkins team builds.
- we've added new layers to the image
- with python3 and pytest and allure-pytest
- we use allure for the reporting so I've just added libs to the image and now there is no need to install in the runtime.
That's basically it.
Now, we need to build the image
Building the image β
In the terminal you need to be in the same folder, where you've created the Dockerfile.
Run bloody command:
docker build -t jenkins-agent:202512 .Space and dot at the end are required, this is not a typo. Dot means current directory.
Looks for the errors, if there is none, then check the creation of the new image:
docker image ls | grep jenkinsYou are expecting to see something like this:
user@server:/opt$ docker image ls | grep jenkins
jenkins-agent 202512 c03899654bad 2 minutes ago 707MBNow, we can use it.
Create a new node on Jenkins side β
Agent needs to be registered at Jenkins control node (controller) which is usually a weak machine that does not handle the workload but provides UI and configuration.
- Go to
/manage/computer/ - Create New node β Remote root directory
/home/jenkins/agent - Labels is the space separated list of words allowing you to select certain agent based on its capabilities.
- I added
pythonlabel to mine.
- I added
- Only build jobs when label expression matching this node.
- Launch method = Launch agent by connecting it to the controller.
- Then enter the created agent
What do we need from there?
- look for
-secret - Look for
-name - Take both values
Command to run the agent β
Update
docker run -d --name jenkins-agent \
-e JENKINS_URL="https://real.jenkins.url/" \
-e JENKINS_AGENT_NAME="just-created-above" \
-e JENKINS_SECRET=PUT_SECRET_HERE \
jenkins-agent:202512Then execute the command.
Agent will connect to the controller.
Using agent in pipelines β
To select agent with python you need to use its label in the pipeline as follows:
pipeline {
agent {
label 'python'
}
// some stuff here
}That's it!