Chapter 32: Jenkins Governance, Troubleshooting and Expert Projects
Chala mitrano, aaj aapan governance (scan library), troubleshooting (start, disk, agent, Git, queue), ani expert project checklist. Ghabru naka.
What you will learn in this chapter
- Scan gate owned by shared library
- Troubleshoot will-not-start, disk full, agent offline, Git auth, stuck queue
- Expert project checklist — not ten new courses
Concepts in this chapter
- 32.1Governance: the scan is not optional
- 32.2Will not start
- 32.3Disk full
- 32.4Agent offline
- 32.5Git auth
- 32.6Queue stuck
- 32.7Expert projects — a checklist, not ten courses
The chapter recap is at the end of the last concept page.
Practice Tasks
Suppose we are on the DevOps team at Safaricom, the telecom and mobile money company, working from Nairobi. Wanjiru Kamau leads the team, and we look after the M-Pesa receipt service. Costs are counted in KES. In the tasks below we do real DevOps jobs on this project using what this lesson teaches. Safaricom is a real company, but this project, the people, servers, IP addresses and numbers are made up for practice.
0 / 12
Easy Declarative Jenkinsfile: build and test
Why: Pipeline as code lives in Git with the app, so every change is reviewed.
What to do: Write a declarative Jenkinsfile: agent any; stage Build runs sh 'mvn -B package'; stage Test runs sh 'mvn test'.
- Start with pipeline { and close it with } at the end.
- Add agent, then stages { } with one stage('Name') { steps { } } per step.
- Put the commands inside steps using sh '...'.
- Count your { and } so every block is closed, then click Check answer.
Easy Read container logs
Why: Logs are the first place to look when a container misbehaves.
What to do: Show the last 100 log lines of the container m-pesa-receipt.
- Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
- Write the tool name, then the sub-command (the action word).
- Add the flags the task needs, each followed by its value.
- Add names, files or paths at the end, then click Check answer.
Easy Pod logs
Why: Logs show what the app printed before it failed.
What to do: Show the last 100 log lines of pod m-pesa-receipt-7d9f in safaricom-prod.
- Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
- Write the tool name, then the sub-command (the action word).
- Add the flags the task needs, each followed by its value.
- Add names, files or paths at the end, then click Check answer.
Medium Follow logs live
Why: Watching logs live while you test shows errors the moment they happen.
What to do: Follow the logs of m-pesa-receipt live, starting from the last 20 lines.
- Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
- Write the tool name, then the sub-command (the action word).
- Add the flags the task needs, each followed by its value.
- Add names, files or paths at the end, then click Check answer.
Medium Always archive, alert on failure
Why: post blocks run after the stages, whatever the result.
What to do: Declarative pipeline, agent any, one stage Build with sh 'make'. Add post: always → archiveArtifacts artifacts: 'build/**'; failure → echo 'Build failed'.
- Start with pipeline { and close it with } at the end.
- Add agent, then stages { } with one stage('Name') { steps { } } per step.
- Put the commands inside steps using sh '...'.
- Count your { and } so every block is closed, then click Check answer.
Medium Run the build inside a Docker agent
Why: A Docker agent gives a clean, versioned toolchain for every build.
What to do: Declarative pipeline with agent docker { image 'maven:3.9-eclipse-temurin-21' } and stage Build running sh 'mvn -B verify'.
- Start with pipeline { and close it with } at the end.
- Add agent, then stages { } with one stage('Name') { steps { } } per step.
- Put the commands inside steps using sh '...'.
- Count your { and } so every block is closed, then click Check answer.
Medium Pipeline environment variables
Why: Values set once in environment are reused by every stage.
What to do: Declarative pipeline, agent any, environment with IMAGE = 'safaricom/m-pesa-receipt' and TAG = '1.5.6', and stage Image running sh 'docker build -t $IMAGE:$TAG .'.
- Start with pipeline { and close it with } at the end.
- Add agent, then stages { } with one stage('Name') { steps { } } per step.
- Put the commands inside steps using sh '...'.
- Count your { and } so every block is closed, then click Check answer.
Medium Deploy only from main
Why: Feature branches are built and tested but never deployed.
What to do: Declarative pipeline, agent any, stage Deploy with when { branch 'main' } and steps sh './deploy.sh af-south-1'.
- Start with pipeline { and close it with } at the end.
- Add agent, then stages { } with one stage('Name') { steps { } } per step.
- Put the commands inside steps using sh '...'.
- Count your { and } so every block is closed, then click Check answer.
Hard Logs of the crashed container
Why: In CrashLoopBackOff the useful logs belong to the previous run.
What to do: Show the logs of the previous (crashed) container of pod m-pesa-receipt-7d9f in safaricom-prod.
- Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
- Write the tool name, then the sub-command (the action word).
- Add the flags the task needs, each followed by its value.
- Add names, files or paths at the end, then click Check answer.
Hard Use Jenkins credentials safely
Why: withCredentials masks the password and removes it after the block.
What to do: Inside stage Push steps, use withCredentials with usernamePassword(credentialsId: 'reg-cred', usernameVariable: 'U', passwordVariable: 'P') and run sh 'echo $P | docker login -u $U --password-stdin registry.safaricom.example.com'. Wrap it in a full declarative pipeline with agent any.
- Start with pipeline { and close it with } at the end.
- Add agent, then stages { } with one stage('Name') { steps { } } per step.
- Put the commands inside steps using sh '...'.
- Count your { and } so every block is closed, then click Check answer.
Hard Manual approval before production
Why: A human sign-off stops an accidental production release.
What to do: Declarative pipeline, agent any, stage Prod with input message 'Deploy to production?' and steps sh './deploy.sh prod'.
- Start with pipeline { and close it with } at the end.
- Add agent, then stages { } with one stage('Name') { steps { } } per step.
- Put the commands inside steps using sh '...'.
- Count your { and } so every block is closed, then click Check answer.
Hard Parallel test stages
Why: Running unit and lint at the same time halves feedback time.
What to do: Declarative pipeline, agent any, stage Checks containing parallel with stage Unit (sh 'npm test') and stage Lint (sh 'npm run lint').
- Start with pipeline { and close it with } at the end.
- Add agent, then stages { } with one stage('Name') { steps { } } per step.
- Put the commands inside steps using sh '...'.
- Count your { and } so every block is closed, then click Check answer.
Ravi Sir's Cards: 17 revision, interview and comparison cards for this chapter · मराठी cards