Skip to content
Back to Deployment

Jenkins CI/CD

Self-hosted CI/CD with Jenkinsfile, plugins, and distributed agents.

CI/CDAdvanced

Why

Jenkins is the most extensible CI/CD with 1800+ plugins. Jenkinsfile (Groovy DSL) defines pipelines as code.

Self-hosted gives full control over runners.

When

Use Jenkins for complex enterprise CI, on-prem requirements, and teams already using it. Avoid for new cloud-native (use GH Actions).

How

1. Install — Jenkins WAR or Docker 2. Pipeline — Jenkinsfile in repo 3. Agent — distributed build agents 4. Plugin — install needed plugins 5. Credentials — Jenkins credential store 6. Multibranch — auto-discover branches 7. Declarative — pipeline { } syntax

Example

# Jenkinsfile pipeline { agent any stages { stage('Build') { steps { sh 'npm ci && npm run build' } } stage('Test') { steps { sh 'npm test' } } stage('Deploy') { when: { branch 'main' } steps { withCredentials([string(credentialsId: 'vercel-token', variable: 'TOKEN')]) { sh 'npx vercel --prod --token $TOKEN' } } } } } # Run Jenkins in Docker docker run -d -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts

Common Problems

  • ⚠Plugin hell — too many plugins, slow and fragile, minimize plugins
  • ⚠Jenkinsfile syntax errors — use Jenkins VS Code extension for validation
  • ⚠Configuration drift between environments — use infrastructure-as-code (Terraform/Pulumi) to keep dev/staging/prod identical

Best Practices

  • ✓Use declarative pipeline — cleaner syntax, better IDE support
  • ✓Minimize plugins — each plugin adds risk, only install what you need
  • ✓Set up health checks and graceful shutdown — handle SIGTERM to drain in-flight requests before exit

FAQ