الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

jenkins

The classic open-source automation server: pipelines as code in a Jenkinsfile, thousands of plugins, agents on any OS.

المستوى
خدمة DevSecOps
المجموعة
Git و CI/CD
يحتاج root
للتغييرات
الحزمة
jenkins

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

Jenkins is a Java web app (port 8080) that runs jobs. Modern jobs are Pipelines defined in a Jenkinsfile in the repository (declarative syntax: pipeline { agent … stages { … } }). The controller schedules work; agents (VMs, containers, Kubernetes pods) run it. Many companies still run Jenkins, so you meet it in DevOps jobs even when new projects use GitHub Actions or GitLab CI.

Jenkins is a common attack target: keep it and its plugins updated, never open it to the internet without SSO, and do not run builds on the controller.

طريقة الكتابة

systemctl {start|status} jenkins
java -jar jenkins-cli.jar -s URL -auth USER:TOKEN COMMAND

الأجزاء الرئيسية

Jenkinsfile blocks

pipeline
The whole declarative pipeline.
agent
Where it runs (any, label, docker, kubernetes).
stages / stage / steps
The work.
environment
Variables, also credentials('id').
when
Conditions (branch, tag, changes).
post
Steps after the run (always, success, failure).
options
timeout, retries, build history.
parameters
Inputs for a build.

الخيارات 7

الأكثر استخدامًا

CLI commands

who-am-i
Check the login.
build JOB [-s] [-p K=V]
Start a build (wait with -s).
console JOB [N]
Show console output.
list-jobs
List jobs.
install-plugin NAME
Install a plugin.
safe-restart
Restart when builds are done.
reload-configuration
Reload config from disk.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Install on RHEL

    curl -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 install -y java-21-openjdk jenkins
    systemctl enable --now jenkins
    cat /var/lib/jenkins/secrets/initialAdminPassword
  2. 2Run Jenkins in a container

    docker run -d --name jenkins -p 127.0.0.1:8080:8080 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts-jdk21
  3. 3A declarative Jenkinsfile

    cat Jenkinsfile
    pipeline {
      agent { docker { image 'python:3.12-slim' } }
      options { timeout(time: 20, unit: 'MINUTES') }
      stages {
        stage('Test')  { steps { sh 'pip install -r requirements.txt && pytest -q' } }
        stage('Scan')  { steps { sh 'trivy fs --exit-code 1 --severity HIGH,CRITICAL .' } }
        stage('Build') { when { branch 'main' } steps { sh 'docker build -t shop:$BUILD_NUMBER .' } }
      }
      post { failure { echo 'Build failed' } }
    }
  4. 4Use stored credentials safely

    cat Jenkinsfile
        stage('Push') {
          steps {
            withCredentials([usernamePassword(credentialsId: 'ghcr', usernameVariable: 'U', passwordVariable: 'P')]) {
              sh 'echo "$P" | docker login ghcr.io -u "$U" --password-stdin'
            }
          }
        }
  5. 5Use the CLI with an API token

    curl -O http://localhost:8080/jnlp/jenkins-cli.jar
    java -jar jenkins-cli.jar -s http://localhost:8080 -auth admin:API_TOKEN who-am-i
    java -jar jenkins-cli.jar -s http://localhost:8080 -auth admin:API_TOKEN build shop/main -s
  6. 6Start a build with the REST API

    curl -X POST -u admin:API_TOKEN http://localhost:8080/job/shop/job/main/build
  7. 7Configuration as Code (JCasC)

    cat jenkins.yaml
    jenkins:
      numExecutors: 0
      securityRealm:
        local:
          allowsSignup: false
    unclassified:
      location:
        url: https://ci.example.com/
  8. 8Read the logs

    journalctl -u jenkins -n 50
  9. 9Back up Jenkins

    tar czf jenkins-backup-$(date +%F).tgz -C /var/lib jenkins --exclude='jenkins/workspace'
  10. 10Run agents as Kubernetes pods

    cat Jenkinsfile
    pipeline {
      agent { kubernetes { yamlFile 'ci/pod.yaml' } }
      stages { stage('Test') { steps { container('python') { sh 'pytest -q' } } } }
    }

انتبه

  • Set controller executors to 0; run builds only on agents.
  • Update plugins often — most Jenkins CVEs are in plugins.
  • sh "echo ${PASSWORD}" with double quotes leaks the secret into logs; use single quotes so the shell expands it.

الملفات

/var/lib/jenkins/
JENKINS_HOME: jobs, plugins, secrets.
/var/lib/jenkins/secrets/initialAdminPassword
First-start password.
Jenkinsfile
The pipeline in the repository.

نصائح للحفظ

  • Use the Kubernetes plugin for agents as pods; each build gets a clean environment.

رموز الخروج

0Success (CLI).
1Error.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man 8 jenkins