🔧
CI/CD & GitOps

Jenkins

Open-source automation server for CI/CD pipelines

🐧 Linux🍎 Mac🪟 Windows📋 Quick reference →
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

Alternative — team standard for CI/CD

What is this?

Jenkins automatically builds, tests, and deploys your code whenever you push changes.

📁

Config files for Jenkins

Where to create or edit the main configuration — paths below match the setup steps.

  • Jenkinsfile

    Location: Repository root (Pipeline as Code) or job config in UI

    Declarative or scripted pipeline stages

  • /var/lib/jenkins/config.xml

    Location: Linux server — Jenkins home

    Global Jenkins settings (managed by UI)

📥

Step 01

Install Jenkins

(01)Install Java (required)

Linux
1# Ubuntu / Debian
2sudo apt-get update
3sudo apt-get install -y openjdk-21-jdk
4
5# RHEL / Fedora
6sudo dnf install -y java-21-openjdk

(02)Install Jenkins

Linux
1# Ubuntu / Debian
2curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
3echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
4sudo apt-get update
5sudo apt-get install -y jenkins
6sudo systemctl enable jenkins
7sudo systemctl start jenkins

(03)Get Initial Admin Password

Linux
1sudo cat /var/lib/jenkins/secrets/initialAdminPassword
⚙️

Step 02

Pipeline as Code

(01)Add Jenkinsfile to repo root

For Pipeline jobs, place Jenkinsfile in the repository root. Jenkins checks out the repo and runs the file.

Linux
1cat > Jenkinsfile << 'EOF'
2pipeline {
3 agent any
4 stages {
5 stage('Build') {
6 steps {
7 sh 'npm ci && npm test'
8 }
9 }
10 }
11}
12EOF
13git add Jenkinsfile && git commit -m "Add Jenkins pipeline" && git push
✅

Step 03

Verify Installation

(01)Access Jenkins UI

Linux
1# Open http://localhost:8080 in your browser

(02)Check Service Status

Linux
1sudo systemctl status jenkins
⚡

Step 04

Manage Jenkins

(01)Service Control

Linux
1sudo systemctl start jenkins
2sudo systemctl stop jenkins
3sudo systemctl restart jenkins
4sudo systemctl status jenkins

(02)View Logs

Linux
1sudo journalctl -u jenkins -f

(03)CLI Operations

Linux
1# Download CLI jar from Jenkins UI, then:
2java -jar jenkins-cli.jar -s http://localhost:8080/ help
3java -jar jenkins-cli.jar -s http://localhost:8080/ list-jobs
🔧

Step 05

Common Problems

#1Jenkins won't start / port 8080 in use

Linux
1sudo systemctl status jenkins
2sudo journalctl -u jenkins -n 50
3sudo lsof -i :8080

📋Config templates

4 YAML templates for Jenkins. Copy and deploy after setup.

4 ready-to-copy templates. Expand one, copy the YAML, then run the deploy commands.

.github/workflows/ci.yml

Node.js — install, test, build Docker image, push to registry

yaml
1name: CI Pipeline
2
3on:
4 push:
5 branches: [main, develop]
6 pull_request:
7 branches: [main]
8
9env:
10 REGISTRY: ghcr.io
11 IMAGE_NAME: ${{ github.repository }}
12
13jobs:
14 build-and-test:
15 runs-on: ubuntu-latest
16 steps:
17 - uses: actions/checkout@v4
18
19 - name: Setup Node.js
20 uses: actions/setup-node@v4
21 with:
22 node-version: "20"
23 cache: "npm"
24
25 - name: Install dependencies
26 run: npm ci
27
28 - name: Run tests
29 run: npm test
30
31 - name: Build Docker image
32 run: docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} .
33
34 - name: Log in to GitHub Container Registry
35 if: github.event_name == 'push' && github.ref == 'refs/heads/main'
36 uses: docker/login-action@v3
37 with:
38 registry: ${{ env.REGISTRY }}
39 username: ${{ github.actor }}
40 password: ${{ secrets.GITHUB_TOKEN }}
41
42 - name: Push image
43 if: github.event_name == 'push' && github.ref == 'refs/heads/main'
44 run: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}

.github/workflows/java-ci.yml

Spring Boot / Maven — compile, test, package JAR

yaml
1name: Java CI
2
3on:
4 push:
5 branches: [main]
6 pull_request:
7 branches: [main]
8
9jobs:
10 build:
11 runs-on: ubuntu-latest
12 steps:
13 - uses: actions/checkout@v4
14
15 - name: Set up JDK 21
16 uses: actions/setup-java@v4
17 with:
18 java-version: "21"
19 distribution: "temurin"
20 cache: maven
21
22 - name: Build and test
23 run: mvn -B verify
24
25 - name: Upload JAR artifact
26 uses: actions/upload-artifact@v4
27 with:
28 name: app-jar
29 path: target/*.jar
📄

Step 01

Use the Workflow

(01)Add workflow to your repo

Linux
1mkdir -p .github/workflows
2cp ci.yml .github/workflows/ci.yml
3git add .github/workflows/
4git commit -m "Add CI pipeline"
5git push origin main
6# View runs: GitHub → Actions tab

(02)Add secrets (for registry push)

Linux
1# GitHub repo → Settings → Secrets and variables → Actions
2# GITHUB_TOKEN is automatic; add DOCKERHUB_TOKEN if pushing to Docker Hub