jenkins

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Jenkins

Jenkins

Jenkins is the grandfather of CI, but still widely used in enterprise. In 2025, it runs primarily as Code (Jenkinsfile) and often on Kubernetes.
Jenkins是CI领域的“鼻祖”,但如今在企业中仍被广泛使用。到2025年,它主要以代码(Jenkinsfile)的形式运行,且常部署在Kubernetes上。

When to Use

适用场景

  • Legacy/Enterprise: You have massive, complex, custom requirements that only Jenkins plugins can handle.
  • Fineness of Control: You need absolute control over the build environment.
  • On-Premise: You cannot use Cloud CI.
  • 遗留系统/企业环境:你有大规模、复杂的自定义需求,只有Jenkins插件能满足。
  • 精细控制:你需要对构建环境拥有绝对控制权。
  • 本地部署:你无法使用云原生CI工具。

Quick Start (Declarative Pipeline)

快速入门(声明式流水线)

groovy
// Jenkinsfile
pipeline {
    agent { docker { image 'node:20' } }
    stages {
        stage('Build') {
            steps {
                sh 'npm ci'
                sh 'npm run build'
            }
        }
    }
}
groovy
// Jenkinsfile
pipeline {
    agent { docker { image 'node:20' } }
    stages {
        stage('Build') {
            steps {
                sh 'npm ci'
                sh 'npm run build'
            }
        }
    }
}

Core Concepts

核心概念

Master / Agent

Master / Agent

Master (Controller) orchestrates. Agents (Executors) run the jobs. 2025 Best Practice: Ephemeral Agents on Kubernetes.
Master(控制器)负责编排任务,Agent(执行器)负责运行作业。2025年最佳实践:在Kubernetes上使用临时Agent。

Plugins

插件

The ecosystem is huge. Blue Ocean, Credentials Binding, Git.
Jenkins的插件生态系统非常庞大,比如Blue Ocean、Credentials Binding、Git等。

CasC (Configuration as Code)

CasC(配置即代码)

Configure the Jenkins Master itself using YAML, not the UI.
使用YAML而非UI来配置Jenkins Master本身。

Best Practices (2025)

2025年最佳实践

Do:
  • Use Declarative Pipelines: Avoid Scripted Pipelines unless absolutely necessary.
  • Use Ephemeral Agents: Spin up a Pod for each build, destroy it after. No "Snowflake" build servers.
  • Use Shared Libraries: For reusable Groovy logic across pipelines.
Don't:
  • Don't configure jobs in UI: Always use
    Jenkinsfile
    .
  • Don't overload the Master: Run zero builds on the built-in controller node.
建议
  • 使用声明式流水线:除非绝对必要,否则避免使用脚本式流水线。
  • 使用临时Agent:为每个构建启动一个Pod,构建完成后销毁。不要使用“独一无二”的构建服务器。
  • 使用共享库:用于在多个流水线之间复用Groovy逻辑。
不建议
  • 不要在UI中配置作业:始终使用
    Jenkinsfile
  • 不要让Master过载:在内置控制器节点上运行个构建任务。

References

参考资料