Jenkins

💤0
Lv 10 XP
← 🔁 CI/CD & DevOps · Pipelines

Jenkins

Advanced ⭐ 120 XP ⏱ 16 min #cicd#jenkins#pipelines

The veteran automation server — pipelines as code with Jenkinsfiles and agents.

📖Theory

Jenkins is a long-established, self-hosted automation server. Its strength is a massive plugin ecosystem and flexibility; its cost is that you run and maintain the controller and agents.

Modern Jenkins uses Pipeline as code — a Jenkinsfile (declarative syntax) checked into the repo. A controller schedules work onto agents (nodes/ executors). You define stages and steps, store secrets in the credentials store, and trigger builds by SCM webhooks or polling.

🌍Real-World Example
pipeline {
  agent any
  stages {
    stage('Build') { steps { sh 'npm ci' } }
    stage('Test')  { steps { sh 'npm test' } }
    stage('Deploy') {
      when { branch 'main' }
      steps {
        withCredentials([string(credentialsId: 'deploy-token', variable: 'TOKEN')]) {
          sh './deploy.sh'
        }
      }
    }
  }
  post { failure { echo 'Build failed' } }
}
✍️Hands-On Exercise
  1. Write a declarative Jenkinsfile with build, test, and deploy stages.
  2. Restrict the deploy stage to the main branch with when.
  3. Use withCredentials to inject a secret without printing it.
  4. Compare Jenkins to a hosted CI service in two sentences.
🧾Cheat Sheet
ConceptDetail
JenkinsfilePipeline as code (Groovy)
ControllerSchedules builds
Agent / executorRuns the work
stages / stepsPipeline structure
PluginsExtend functionality
Credentials storeManage secrets
whenConditional stage
💬Common Interview Questions
What is a Jenkinsfile?

A pipeline definition as code, checked into the repo, describing stages and steps in declarative (or scripted) syntax — so the build process is versioned alongside the code.

What's a trade-off of Jenkins versus hosted CI?

Jenkins offers maximum flexibility and a huge plugin ecosystem but requires you to host, secure, and maintain the controller and agents — work that managed CI services handle for you.

📚Official Documentation

📝 My notes on this topic

Auto-saves as you type