هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Know it before you install
The Jenkins controller is a Java web app that keeps the jobs, plugins and credentials. Agents (other machines or containers) run the builds. A pipeline is written as code in a Jenkinsfile in your Git repository.
| Item | Value |
|---|---|
| Package | jenkins (from pkg.jenkins.io, LTS = "stable") |
| Needs | Java 17 or 21 (java-21-openjdk / openjdk-21-jre) and fontconfig |
| Service | jenkins.service, runs as user jenkins |
| Data (JENKINS_HOME) | /var/lib/jenkins/ — jobs, plugins, credentials, config |
| Port | 8080/tcp (web), 50000/tcp (inbound agents, only if you use them) |
| Settings | systemctl edit jenkins (port, Java options) |
| Logs | journalctl -u jenkins |
What you need: 2 CPU, 4 GB RAM and 50 GB disk for a small team (builds and artifacts fill the disk).
Install on RHEL, Rocky, Alma and Fedora
curl -fsSL -o /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
dnf -y install fontconfig java-21-openjdk
dnf -y install jenkins
systemctl daemon-reload
systemctl enable --now jenkins
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reloadملاحظة
Jenkins changes its package signing key from time to time. If dnf or apt says the key is wrong or expired, take the current key file name from pkg.jenkins.io and import it again.
Install on Ubuntu and Debian
apt-get update
apt-get install -y fontconfig openjdk-21-jre curl
curl -fsSL -o /etc/apt/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/etc/apt/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/" > /etc/apt/sources.list.d/jenkins.list
apt-get update
apt-get install -y jenkins
systemctl status jenkins --no-pagerفي العمل
For a lab, the container is faster: docker run -d --name jenkins -p 127.0.0.1:8080:8080 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts-jdk21.
The setup wizard
Open http://SERVER:8080. Jenkins asks for the first admin password:
cat /var/lib/jenkins/secrets/initialAdminPassword
3f0c5e6b2a8d4c9e8f1a7b6c5d4e3f2aThen:
- Choose Install suggested plugins (Git, Pipeline, Credentials, …).
- Create your own admin user (not
admin/admin). - Set the Jenkins URL to the final HTTPS address, for example
https://ci.example.com/.
First configuration: the settings to make first
Make these settings in Manage Jenkins before the first real job:
| Where | Setting | Why |
|---|---|---|
| Nodes → Built-In Node → Configure | Number of executors = 0 | Builds never run on the controller, so a build can not read its secrets and config. |
| Security | Authorization: Matrix-based or Role-based (plugin) | Each team gets only the rights it needs; anonymous users get nothing. |
| Security | Agents → TCP port: disable (or fixed port) | Close port 50000 when agents connect over SSH. |
| Credentials | Store Git keys, tokens and passwords here | Pipelines use them by ID, never in plain text. |
| System | Jenkins URL, admin email, global build discarders | Correct links; old builds are deleted automatically. |
| Plugins | Update all, remove plugins you do not use | Most Jenkins CVEs are in plugins. |
Put Jenkins behind Nginx with HTTPS and listen only on localhost. Change the port and the listen address with a systemd override:
systemctl edit jenkins[Service]
Environment="JENKINS_LISTEN_ADDRESS=127.0.0.1"
Environment="JENKINS_PORT=8080"
Environment="JAVA_OPTS=-Djava.awt.headless=true -Xmx2g"server {
listen 443 ssl;
server_name ci.example.com;
ssl_certificate /etc/letsencrypt/live/ci.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ci.example.com/privkey.pem;
client_max_body_size 100m;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_http_version 1.1;
proxy_request_buffering off;
}
}Add an agent
The easiest agent is a Linux machine over SSH with Java and Git:
dnf -y install java-21-openjdk git
useradd -m -s /bin/bash jenkins
mkdir -p /home/jenkins/.ssh && chmod 700 /home/jenkins/.sshPut the public key of a Jenkins credential in /home/jenkins/.ssh/authorized_keys on the agent. Then in Jenkins: Nodes → New Node → Permanent Agent, launch method Launch agents via SSH, a label like linux docker, and the remote root /home/jenkins/agent.
Your first pipeline
Put this Jenkinsfile in the root of your Git repository:
pipeline {
agent { label 'linux' }
options {
timeout(time: 30, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr: '20'))
}
stages {
stage('Test') {
steps { sh 'make test' }
}
stage('Build image') {
steps { sh 'docker build -t registry.example.com/shop:${GIT_COMMIT} .' }
}
stage('Scan') {
steps { sh 'trivy image --exit-code 1 --severity HIGH,CRITICAL registry.example.com/shop:${GIT_COMMIT}' }
}
stage('Deploy') {
when { branch 'main' }
steps {
input message: 'Deploy to production?'
withCredentials([file(credentialsId: 'kubeconfig-prod', variable: 'KUBECONFIG')]) {
sh 'kubectl set image deploy/shop shop=registry.example.com/shop:${GIT_COMMIT}'
}
}
}
}
}In Jenkins: New Item → Multibranch Pipeline, add the Git repository and its credential. Jenkins finds every branch with a Jenkinsfile and builds it. Add a webhook in GitHub/GitLab to https://ci.example.com/github-webhook/ (GitHub plugin) so builds start at once.
Real uses at work:
- Build, test and scan every pull request; deploy
mainafter approval. - Night jobs: backups, reports, dependency updates.
- Shared libraries: one pipeline code for many projects.
Make it safe
Security checklist:
- 0 executors on the controller; builds only on agents.
- HTTPS (Nginx) and Jenkins on
127.0.0.1; no public port 8080. - Matrix or role-based rights; no anonymous read; SSO/LDAP if you can.
- Secrets only in Credentials;
withCredentialsmasks them in logs. - Update Jenkins LTS and the plugins every month; read the Jenkins security advisories.
- Back up
JENKINS_HOME(at leastconfig.xml,jobs/,credentials.xml,secrets/,plugins/). - Limit the Script Console to admins; it can run any code on the controller.
Update, back up and remove
dnf -y upgrade jenkins
apt-get install --only-upgrade -y jenkins
systemctl stop jenkins
tar -czf /backup/jenkins-$(date +%F).tar.gz -C /var/lib jenkins --exclude='jenkins/workspace' --exclude='jenkins/caches'
systemctl start jenkins
dnf -y remove jenkinsانتبه
JENKINS_HOME/secrets/ holds the key that decrypts all credentials. Keep it in the backup, and keep the backup as secret as the passwords themselves.
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
| Service does not start | Wrong or missing Java version. | java -version (17 or 21); journalctl -u jenkins -n 50. |
Address already in use on 8080 | Another app uses the port. | ss -ltnp 'sport = :8080'; change JENKINS_PORT. |
| "It appears that your reverse proxy set up is broken" | Missing proxy headers or wrong Jenkins URL. | Set X-Forwarded-* headers and the Jenkins URL to the HTTPS address. |
No valid crumb was included in the request | CSRF check fails (proxy or old session). | Correct proxy headers; log in again. |
| Plugin errors after an update | Plugin versions do not fit together. | Manage Jenkins → Plugins → update the dependencies; restart. |
| Disk full | Old builds and workspaces. | Build discarder; delete workspace/ of old jobs; agents clean their workspaces. |
| Build waits: "Waiting for next available executor" | No agent with that label is online. | Check Nodes; start the agent; fix the label. |
Next steps
- Quick how-tos: Build a pipeline with a Jenkinsfile.
- Command page: jenkins.
- Practise: Lab: a Jenkins pipeline as code.
- Jenkins at work: The classic automation server, Pipelines in companies.
- What the pipeline uses: Docker, Nginx in front, scan with trivy.
1Why set the executors of the built-in node to 0?
Builds then never run on the controller, so a build can not read the controller's files and secrets.
2Which folder must be in every Jenkins backup, and why is it sensitive?
JENKINS_HOME/secrets/ — it holds the key that decrypts all stored credentials.