Installation de Jenkins
Prérequis
Java
Jenkins nécessite Java 11 ou 17 (LTS recommandé).
# Vérifier la version Java
java -version
# Ubuntu/Debian - Installer OpenJDK 17
sudo apt update
sudo apt install openjdk-17-jdk -y
# CentOS/RHEL
sudo yum install java-17-openjdk-devel -y
# Vérifier
java -version
Ressources minimales
| Composant | Minimum | Recommandé |
|---|---|---|
| CPU | 1 core | 4 cores |
| RAM | 256 MB | 4 GB |
| Disque | 1 GB | 50 GB |
Installation sur Ubuntu/Debian
# 1. Ajouter la clé GPG Jenkins
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
# 2. Ajouter le repository
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
# 3. Installer Jenkins
sudo apt update
sudo apt install jenkins -y
# 4. Démarrer Jenkins
sudo systemctl start jenkins
sudo systemctl enable jenkins
# 5. Vérifier le statut
sudo systemctl status jenkins
# 6. Récupérer le mot de passe initial
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Installation sur CentOS/RHEL
# 1. Ajouter le repository
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
# 2. Installer Jenkins
sudo yum install jenkins -y
# 3. Démarrer Jenkins
sudo systemctl start jenkins
sudo systemctl enable jenkins
# 4. Ouvrir le firewall
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
# 5. Récupérer le mot de passe initial
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Installation avec Docker (Recommandé)
Docker simple
# Créer un volume pour la persistance
docker volume create jenkins_home
# Lancer Jenkins
docker run -d \
--name jenkins \
-p 8080:8080 \
-p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkins/jenkins:lts-jdk17
# Voir les logs et récupérer le mot de passe
docker logs jenkins
Docker Compose
# docker-compose.yml
version: '3.8'
services:
jenkins:
image: jenkins/jenkins:lts-jdk17
container_name: jenkins
restart: unless-stopped
ports:
- "8080:8080"
- "50000:50000"
volumes:
- jenkins_home:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
environment:
- JAVA_OPTS=-Xmx2048m -Xms512m
networks:
- jenkins-network
# Agent Docker (optionnel)
jenkins-agent:
image: jenkins/inbound-agent
container_name: jenkins-agent
restart: unless-stopped
environment:
- JENKINS_URL=http://jenkins:8080
- JENKINS_AGENT_NAME=docker-agent
- JENKINS_SECRET=${AGENT_SECRET}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- jenkins-network
depends_on:
- jenkins
volumes:
jenkins_home:
networks:
jenkins-network:
driver: bridge
# Lancer
docker-compose up -d
# Voir les logs
docker-compose logs -f jenkins
Dockerfile personnalisé
FROM jenkins/jenkins:lts-jdk17
# Passer en root pour les installations
USER root
# Installer Docker CLI
RUN apt-get update && \
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release && \
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list && \
apt-get update && \
apt-get install -y docker-ce-cli && \
rm -rf /var/lib/apt/lists/*
# Installer des outils supplémentaires
RUN apt-get update && \
apt-get install -y \
git \
make \
kubectl && \
rm -rf /var/lib/apt/lists/*
# Installer les plugins recommandés
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN jenkins-plugin-cli --plugin-file /usr/share/jenkins/ref/plugins.txt
# Revenir à l'utilisateur jenkins
USER jenkins
# Skip le wizard de setup
ENV JAVA_OPTS="-Djenkins.install.runSetupWizard=false"
# plugins.txt
git
workflow-aggregator
docker-workflow
kubernetes
blueocean
configuration-as-code
credentials-binding
pipeline-stage-view
Installation sur Kubernetes
Helm Chart
# Ajouter le repo Helm
helm repo add jenkins https://charts.jenkins.io
helm repo update
# Créer le namespace
kubectl create namespace jenkins
# Installer Jenkins
helm install jenkins jenkins/jenkins \
--namespace jenkins \
--set controller.serviceType=LoadBalancer \
--set persistence.size=50Gi \
--set controller.installPlugins[0]=kubernetes \
--set controller.installPlugins[1]=workflow-aggregator \
--set controller.installPlugins[2]=git \
--set controller.installPlugins[3]=configuration-as-code
# Récupérer le mot de passe admin
kubectl exec -n jenkins -it svc/jenkins -c jenkins -- \
cat /run/secrets/additional/chart-admin-password
Values personnalisées
# jenkins-values.yaml
controller:
image: jenkins/jenkins
tag: lts-jdk17
resources:
requests:
cpu: "500m"
memory: "2Gi"
limits:
cpu: "2000m"
memory: "4Gi"
installPlugins:
- kubernetes
- workflow-aggregator
- git
- configuration-as-code
- docker-workflow
- blueocean
- job-dsl
- credentials-binding
JCasC:
configScripts:
welcome-message: |
jenkins:
systemMessage: "Jenkins configured with JCasC"
persistence:
enabled: true
size: 50Gi
storageClass: gp3
agent:
enabled: true
image: jenkins/inbound-agent
tag: latest
helm install jenkins jenkins/jenkins \
--namespace jenkins \
-f jenkins-values.yaml
Configuration initiale
1. Accéder à Jenkins
Ouvrir http://localhost:8080 (ou l'IP du serveur).
2. Déverrouiller Jenkins
# Copier le mot de passe initial
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
# ou pour Docker
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
3. Installer les plugins
Choisir "Install suggested plugins" pour commencer.
4. Créer l'administrateur
- Username: admin
- Password: (choisir un mot de passe fort)
- Full name: Administrator
- Email: [email protected]
5. Configurer l'URL
Définir l'URL Jenkins (ex: http://jenkins.example.com).
Configuration as Code (JCasC)
Automatiser la configuration de Jenkins avec YAML :
# jenkins.yaml
jenkins:
systemMessage: "Jenkins configuré avec JCasC"
securityRealm:
local:
allowsSignup: false
users:
- id: admin
name: Administrator
password: ${JENKINS_ADMIN_PASSWORD}
authorizationStrategy:
globalMatrix:
permissions:
- "Overall/Administer:admin"
- "Overall/Read:authenticated"
numExecutors: 0 # Builds uniquement sur agents
nodes:
- permanent:
name: "linux-agent-1"
remoteFS: "/home/jenkins"
launcher:
ssh:
host: "agent1.example.com"
credentialsId: "ssh-agent-key"
retentionStrategy: "always"
credentials:
system:
domainCredentials:
- credentials:
- usernamePassword:
scope: GLOBAL
id: github-credentials
username: ${GITHUB_USER}
password: ${GITHUB_TOKEN}
- string:
scope: GLOBAL
id: docker-registry-password
secret: ${DOCKER_PASSWORD}
unclassified:
location:
url: https://jenkins.example.com/
adminAddress: [email protected]
gitSCM:
globalConfigName: Jenkins
globalConfigEmail: [email protected]
# Monter le fichier de config
docker run -d \
-v $(pwd)/jenkins.yaml:/var/jenkins_home/jenkins.yaml \
-e CASC_JENKINS_CONFIG=/var/jenkins_home/jenkins.yaml \
-e JENKINS_ADMIN_PASSWORD=supersecret \
jenkins/jenkins:lts-jdk17
Vérification de l'installation
# Vérifier que Jenkins répond
curl -I http://localhost:8080
# Vérifier la version via l'API
curl -s http://localhost:8080/api/json?pretty=true | grep version
# Tester avec l'API (authentifié)
curl -u admin:password http://localhost:8080/api/json
Résumé des ports
| Port | Usage |
|---|---|
| 8080 | Interface web |
| 50000 | Communication agents JNLP |
Résumé
| Méthode | Avantage | Inconvénient |
|---|---|---|
| Package | Simple | Dépendances système |
| Docker | Isolation | Docker requis |
| Kubernetes | Scalable | Complexité |
| WAR | Portable | Manuel |