Agents and Distributed Builds
Master/Agent architecture
Why agents?
- Scalability: Run multiple builds in parallel
- Isolation: Separate environments
- Heterogeneity: Linux, Windows, macOS
- Security: The controller should not run builds
Agent types
Permanent agent (SSH)
An agent installed on a dedicated machine.
JNLP agent
An agent that connects to the controller.
Docker agent
An ephemeral container for a build.
Kubernetes agent
An ephemeral Pod for a build.
Configuring an SSH agent
Prerequisites on the agent
# 1. Installer Java
sudo apt install openjdk-17-jdk -y
# 2. Créer l'utilisateur jenkins
sudo useradd -m -d /home/jenkins -s /bin/bash jenkins
# 3. Créer le répertoire de travail
sudo mkdir -p /home/jenkins/agent
sudo chown jenkins:jenkins /home/jenkins/agent
# 4. Configurer SSH
sudo mkdir -p /home/jenkins/.ssh
# Ajouter la clé publique du controller
echo "ssh-rsa AAAA..." | sudo tee /home/jenkins/.ssh/authorized_keys
sudo chown -R jenkins:jenkins /home/jenkins/.ssh
sudo chmod 700 /home/jenkins/.ssh
sudo chmod 600 /home/jenkins/.ssh/authorized_keys
Configuration in Jenkins
- Manage Jenkins > Manage Nodes and Clouds > New Node
- Configure:
Node name: linux-agent-1
Type: Permanent Agent
# Configuration
Remote root directory: /home/jenkins/agent
Labels: linux docker maven
Usage: Use this node as much as possible
Launch method: Launch agents via SSH
Host: 192.168.1.100
Credentials: jenkins-ssh-key
Host Key Verification Strategy: Known hosts file
Availability: Keep this agent online as much as possible
Via JCasC
# jenkins.yaml
jenkins:
nodes:
- permanent:
name: "linux-agent-1"
remoteFS: "/home/jenkins/agent"
labelString: "linux docker maven"
numExecutors: 4
mode: NORMAL
launcher:
ssh:
host: "192.168.1.100"
port: 22
credentialsId: "jenkins-ssh-key"
sshHostKeyVerificationStrategy:
knownHostsFileKeyVerificationStrategy:
{}
retentionStrategy:
always: {}
JNLP Agent (Inbound)
On the controller
- Create the node in Jenkins
- Copy the connection command
On the agent
# Télécharger l'agent
curl -O http://jenkins:8080/jnlpJars/agent.jar
# Lancer l'agent
java -jar agent.jar \
-jnlpUrl http://jenkins:8080/computer/agent-1/jenkins-agent.jnlp \
-secret <SECRET> \
-workDir /home/jenkins/agent