Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 81

    Jenkins Basics

    Jenkins remains the CI workhorse in many enterprises that host TechLearningPRO-style platforms.

    Course progress0%
    Focus
    12 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Jenkins remains the CI workhorse in many enterprises that host TechLearningPRO-style platforms. A declarative Jenkinsfile in the Orders repo defines stages agents execute: build, test, image, deploy.

    Prefer declarative over scripted pipelines for readability. Run builds on agents/labels, not the controller. Integrate junit reporting and branch conditions so main alone publishes images.

    On Java 21, configure a Temurin JDK tool installation and call the Maven wrapper so agent images stay consistent with developer laptops.

    This lesson covers Jenkins basics you will still meet in interviews and brownfield ops.

    Purpose of this lesson

    Write a declarative Jenkins pipeline that builds, tests, and deploys Boot 3 Orders on Java 21.

    Understanding the topic

    Jenkinsfile-as-code keeps CI reproducible across agents.

    • Declarative pipeline: stages, agents, when conditions.
    • Tools: JDK/Maven installations on the controller config.
    • Post actions: always archive test results.
    • Agents: isolate workloads from the controller JVM.
    • Credentials: Jenkins credentials store — inject, do not hard-code.

    Step-by-step explanation

    1. Add a Jenkinsfile at the Orders repo root.
    2. Configure Temurin 21 as a Jenkins JDK tool.
    3. Run package/test stages; publish JUnit results.
    4. On main, build an image and roll a Kubernetes deployment (or call your CD tool).

    Informative example

    Declarative Jenkinsfile for Orders.

    groovy
    // Jenkinsfile
    pipeline {
    agent any
    tools { jdk 'temurin-21' }
    options { timestamps() }
    stages {
    stage('Build') {
    steps { sh './mvnw -B clean package -DskipTests' }
    }
    stage('Test') {
    steps { sh './mvnw -B test' }
    post {
    always { junit 'target/surefire-reports/*.xml' }
    }
    }
    stage('Image') {
    when { branch 'main' }
    steps {
    sh '''
    ./mvnw -B spring-boot:build-image \
    -Dspring-boot.build-image.imageName=registry.example.com/orders:$BUILD_NUMBER
    '''
    }
    }
    stage('Deploy') {
    when { branch 'main' }
    steps {
    sh 'kubectl set image deployment/orders app=registry.example.com/orders:$BUILD_NUMBER'
    }
    }
    }
    }

    Real-world use

    A TechLearningPRO partner still runs fifty Jenkins jobs on a single controller. Builds queued for an hour until they moved Maven work to labeled agents and limited the controller to orchestration. Pipeline time dropped; the controller stopped OOMing during Monday morning merges.

    Security implications

    Jenkins often has keys to the kingdom.

    • Lock down who can configure credentials and agents.
    • Use folder/folder credentials scoped to Orders only.
    • Rotate registry tokens; never paste them into job console output.

    Best practices

    • Declarative Jenkinsfile in source control.
    • Agents with clean workspaces per build.
    • Credentials binding plugin for registry and kubeconfig access.

    Common mistakes

    • Scripted pipelines nobody can read six months later.
    • Building on the controller node.
    • Plaintext credentials in Jenkinsfile.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    3 questions
    1BeginnerQuestionDeclarative vs scripted Jenkins pipelines?+

    Answer

    Declarative is structured and easier to maintain; scripted is flexible but often becomes unreadable.
    2IntermediateQuestionWhy not build on the Jenkins controller?+

    Answer

    Controller stability matters; heavy builds belong on agents so CI outages do not take down orchestration.
    3BeginnerQuestionHow should secrets appear in a Jenkinsfile?+

    Answer

    Via Jenkins credentials bindings or withCredentials — never hardcoded strings.

    Hands-on exercise

    Lab. Run the Jenkinsfile in a local Jenkins (Docker). Break a test and confirm the stage fails with JUnit trend. On a main-like branch, verify the Image stage runs and Deploy is gated by branch.

    Summary

    Jenkins basics prepare you for enterprise CI around Orders. Next: deploy those images on AWS.

    Ready to mark this lesson complete?Track your journey across the entire course.