Scripts2026年4月11日·1 分钟阅读

Jenkins — The Original Open-Source Automation Server

Jenkins is the original and still widely-used open-source automation server for CI/CD. 2000+ plugins, pipeline-as-code via Jenkinsfile, distributed builds, and first-class support for nearly every build tool. The battle-tested choice for enterprise CI.

SC
Script Depot · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

# Docker
docker run -d --name jenkins -p 8080:8080 -p 50000:50000 \
  -v jenkins-data:/var/jenkins_home \
  jenkins/jenkins:lts-jdk17

# Get initial admin password
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword

# Visit http://localhost:8080 and complete setup

Create a Jenkinsfile in your repo:

pipeline {
  agent any

  environment {
    NODE_VERSION = "20"
  }

  stages {
    stage("Checkout") {
      steps { checkout scm }
    }
    stage("Install") {
      steps { sh "npm ci" }
    }
    stage("Test") {
      steps { sh "npm test" }
      post {
        always {
          junit "test-results/*.xml"
        }
      }
    }
    stage("Build") {
      steps { sh "npm run build" }
    }
    stage("Deploy") {
      when { branch "main" }
      steps { sh "./deploy.sh production" }
    }
  }

  post {
    failure {
      slackSend channel: "#ci", message: "Build failed: ${env.BUILD_URL}"
    }
  }
}
介绍

Jenkins is the original open-source automation server. Created as Hudson in 2004 by Kohsuke Kawaguchi at Sun Microsystems, forked to Jenkins in 2011. Jenkins still powers a huge portion of the worldwide CI/CD workload, especially in enterprise environments thanks to its 2000+ plugin ecosystem and extreme customizability.

What Jenkins Does

  • Pipelines — Jenkinsfile (Groovy) declarative or scripted
  • Freestyle jobs — GUI-configured legacy jobs
  • Distributed builds — controller + agents on multiple machines
  • Plugins — 2000+ for source control, build tools, deploy targets, notifications
  • Multibranch — auto-discover branches and PRs
  • Shared libraries — reusable Groovy libraries across pipelines
  • Credentials store — encrypted secrets management
  • Blue Ocean — modern pipeline UI
  • CloudBees integrations — enterprise extensions

Architecture

Jenkins controller hosts the UI, scheduler, and job configuration. Agents (formerly slaves) execute builds in parallel, connected via JNLP, SSH, or Kubernetes pods. Pipelines are checkpointed — survive controller restarts.

Self-Hosting

# docker-compose.yml
version: "3"
services:
  jenkins:
    image: jenkins/jenkins:lts-jdk17
    ports: ["8080:8080", "50000:50000"]
    volumes:
      - jenkins-data:/var/jenkins_home
    environment:
      JAVA_OPTS: "-Djenkins.install.runSetupWizard=false"
volumes:
  jenkins-data:

Key Features

  • Pipeline-as-code (Jenkinsfile)
  • 2000+ plugins
  • Distributed builds
  • Matrix builds
  • Shared libraries
  • Credentials store
  • Email/Slack/Teams notifications
  • Multi-branch pipelines
  • Auto-scaling agents on Kubernetes
  • LDAP, SAML, OAuth auth

Comparison

CI/CD Hosted Pipeline Ecosystem
Jenkins Self-hosted Jenkinsfile Largest
GitHub Actions Cloud + self-hosted runners YAML Huge
GitLab CI Cloud + self-hosted YAML Large
CircleCI Cloud + enterprise YAML Large
Drone Self-hosted YAML Medium
Woodpecker Self-hosted YAML Growing

常见问题 FAQ

Q: Jenkins 是不是过时了? A: 被 GitHub Actions、GitLab CI 抢走了大量新项目。但 Jenkins 在企业(尤其是有存量 pipeline、严格合规要求)仍然是首选。2000+ plugin 无出其右。

Q: 和 GitHub Actions 比? A: Actions 云原生、YAML 简洁、与 GitHub 深度集成;Jenkins 自托管、Groovy 灵活、插件生态无敌。选择看托管偏好和集成需求。

Q: 性能和内存? A: Java 应用,controller 通常至少 2GB 堆。大规模部署(百万 job)需要调优 JVM 和存储。

来源与致谢 Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产