هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
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
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 10
$ مستخدم عادي# بصلاحية root (أو مع sudo)
1Install on RHEL
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-jdk213A 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' } } }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' } } }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 -s6Start a build with the REST API
curl -X POST -u admin:API_TOKEN http://localhost:8080/job/shop/job/main/build7Configuration as Code (JCasC)
cat jenkins.yaml jenkins: numExecutors: 0 securityRealm: local: allowsSignup: false unclassified: location: url: https://ci.example.com/8Read the logs
journalctl -u jenkins -n 509Back up Jenkins
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.
رموز الخروج
0 | Success (CLI). |
1 | Error. |