(01)Install Java (required)
1# Ubuntu / Debian2sudo apt-get update3sudo apt-get install -y openjdk-21-jdk4 5# RHEL / Fedora6sudo dnf install -y java-21-openjdkOpen-source automation server for CI/CD pipelines
Alternative — team standard for CI/CD
What is this?
Jenkins automatically builds, tests, and deploys your code whenever you push changes.
Where to create or edit the main configuration — paths below match the setup steps.
JenkinsfileLocation: Repository root (Pipeline as Code) or job config in UI
Declarative or scripted pipeline stages
/var/lib/jenkins/config.xmlLocation: Linux server — Jenkins home
Global Jenkins settings (managed by UI)
Step 01
1# Ubuntu / Debian2sudo apt-get update3sudo apt-get install -y openjdk-21-jdk4 5# RHEL / Fedora6sudo dnf install -y java-21-openjdk1# Ubuntu / Debian2curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null3echo 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/null4sudo apt-get update5sudo apt-get install -y jenkins6sudo systemctl enable jenkins7sudo systemctl start jenkins1sudo cat /var/lib/jenkins/secrets/initialAdminPasswordStep 02
For Pipeline jobs, place Jenkinsfile in the repository root. Jenkins checks out the repo and runs the file.
1cat > Jenkinsfile << 'EOF'2pipeline {3 agent any4 stages {5 stage('Build') {6 steps {7 sh 'npm ci && npm test'8 }9 }10 }11}12EOF13git add Jenkinsfile && git commit -m "Add Jenkins pipeline" && git pushStep 03
1# Open http://localhost:8080 in your browser1sudo systemctl status jenkinsStep 04
1sudo systemctl start jenkins2sudo systemctl stop jenkins3sudo systemctl restart jenkins4sudo systemctl status jenkins1sudo journalctl -u jenkins -f1# Download CLI jar from Jenkins UI, then:2java -jar jenkins-cli.jar -s http://localhost:8080/ help3java -jar jenkins-cli.jar -s http://localhost:8080/ list-jobsStep 05
1sudo systemctl status jenkins2sudo journalctl -u jenkins -n 503sudo lsof -i :80804 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
1name: CI Pipeline2 3on:4 push:5 branches: [main, develop]6 pull_request:7 branches: [main]8 9env:10 REGISTRY: ghcr.io11 IMAGE_NAME: ${{ github.repository }}12 13jobs:14 build-and-test:15 runs-on: ubuntu-latest16 steps:17 - uses: actions/checkout@v418 19 - name: Setup Node.js20 uses: actions/setup-node@v421 with:22 node-version: "20"23 cache: "npm"24 25 - name: Install dependencies26 run: npm ci27 28 - name: Run tests29 run: npm test30 31 - name: Build Docker image32 run: docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} .33 34 - name: Log in to GitHub Container Registry35 if: github.event_name == 'push' && github.ref == 'refs/heads/main'36 uses: docker/login-action@v337 with:38 registry: ${{ env.REGISTRY }}39 username: ${{ github.actor }}40 password: ${{ secrets.GITHUB_TOKEN }}41 42 - name: Push image43 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
1name: Java CI2 3on:4 push:5 branches: [main]6 pull_request:7 branches: [main]8 9jobs:10 build:11 runs-on: ubuntu-latest12 steps:13 - uses: actions/checkout@v414 15 - name: Set up JDK 2116 uses: actions/setup-java@v417 with:18 java-version: "21"19 distribution: "temurin"20 cache: maven21 22 - name: Build and test23 run: mvn -B verify24 25 - name: Upload JAR artifact26 uses: actions/upload-artifact@v427 with:28 name: app-jar29 path: target/*.jarStep 01
1mkdir -p .github/workflows2cp ci.yml .github/workflows/ci.yml3git add .github/workflows/4git commit -m "Add CI pipeline"5git push origin main6# View runs: GitHub → Actions tab1# GitHub repo → Settings → Secrets and variables → Actions2# GITHUB_TOKEN is automatic; add DOCKERHUB_TOKEN if pushing to Docker Hub