Jenkins Basics
Jenkins remains the CI workhorse in many enterprises that host TechLearningPRO-style platforms.
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
- Add a Jenkinsfile at the Orders repo root.
- Configure Temurin 21 as a Jenkins JDK tool.
- Run package/test stages; publish JUnit results.
- On main, build an image and roll a Kubernetes deployment (or call your CD tool).
Informative example
Declarative Jenkinsfile for Orders.
// Jenkinsfilepipeline {agent anytools { 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.
1BeginnerQuestionDeclarative vs scripted Jenkins pipelines?+
Answer
2IntermediateQuestionWhy not build on the Jenkins controller?+
Answer
3BeginnerQuestionHow should secrets appear in a Jenkinsfile?+
Answer
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.