80.1 Project 67: Install Jenkins with agents
Friends, a controller alone cannot run every build. Today we install Jenkins LTS, unlock it, create two SSH agents with labels, and run a smoke job on each agent.
मित्रांनो, फक्त controller सर्व builds चालवू शकत नाही. आज Jenkins LTS, unlock, दोन SSH agents with labels, आणि प्रत्येक agent वर smoke job.
दोस्तों, अकेला controller हर build नहीं चला सकता. आज Jenkins LTS, unlock, दो SSH agents with labels, और हर agent पर smoke job.
What you will build in this project
- Install Jenkins LTS on the controller.
- Unlock and install suggested plugins.
- Attach two SSH agents with labels.
- Run a smoke job on each agent.
1. Start from a real company story
At TCS in Pune, every Maven job ran on the controller. Disk filled during a release week and the UI froze.
Rough delay: about ₹12 lakh in slipped delivery that sprint.
Meera split builds onto labelled agents and kept the controller thin.
Today we install Jenkins the same way.
Ravindra Bagale's Tip
Students open port 8080 to the whole internet without a reverse proxy. Put Nginx or an ALB in front and lock the security group. Keep that habit.
Students 8080 थेट internet वर उघडतात. Nginx किंवा ALB समोर ठेवा आणि security group lock करा. सवय ठेवा.
Students 8080 सीधे internet पर खोलते हैं. सामने Nginx या ALB रखें और security group lock करें. आदत रखिए.
2. Start and prepare
Step 1: Why agents
Why: Controller disk and CPU are limited. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: echo the problem then sketch the layout. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 1: a1
Type this:
echo 'Controller schedules; agents execute builds'
You will see:
Controller schedules; agents execute builds
What it means: Why.
Example 2: a2
Type this:
mkdir -p /tmp/jen67/{controller,agents,jobs} && ls /tmp/jen67
You will see:
agents\ncontroller\njobs
What it means: Folders.
Example 3: a3
Type this:
echo 'Today: LTS install, unlock, two SSH agents, smoke jobs'
You will see:
Today: LTS install, unlock, two SSH agents, smoke jobs
What it means: Scope.
Step 2: Install controller tip
Why: Package and service. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: apt install tips. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 4: b1
Type this:
echo 'curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc'
You will see:
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc
What it means: Key tip.
Example 5: b2
Type this:
echo 'sudo apt-get update && sudo apt-get install -y openjdk-17-jdk jenkins'
You will see:
sudo apt-get update && sudo apt-get install -y openjdk-17-jdk jenkins
What it means: Install tip.
Example 6: b3
Type this:
printf '%s\n' 'systemctl enable --now jenkins' 'systemctl status jenkins --no-pager | head -5' > /tmp/jen67/controller/SERVICE.txt && cat /tmp/jen67/controller/SERVICE.txt
You will see:
systemctl enable --now jenkins
What it means: Service.
Step 3: Unlock Jenkins
Why: initialAdminPassword. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: read the secret file tip. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 7: c1
Type this:
echo 'sudo cat /var/lib/jenkins/secrets/initialAdminPassword'
You will see:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
What it means: Unlock tip.
Example 8: c2
Type this:
printf '%s\n' 'Open http://CONTROLLER:8080' 'Paste the password' 'Install suggested plugins' 'Create first admin user' > /tmp/jen67/controller/UNLOCK.txt && cat /tmp/jen67/controller/UNLOCK.txt
You will see:
Install suggested plugins
What it means: Steps.
Example 9: c3
Type this:
echo 'Rotate the admin password after first login — never leave the initial one'
You will see:
Rotate the admin password after first login — never leave the initial one
What it means: Habit.
3. Build the main pieces
Step 4: SSH key for agents
Why: Passwordless agent launch. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: keygen tips. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 10: d1
Type this:
echo 'ssh-keygen -t ed25519 -f /tmp/jen67/controller/jenkins_agent -N ""'
You will see:
ssh-keygen -t ed25519 -f /tmp/jen67/controller/jenkins_agent -N ""
What it means: Key.
Example 11: d2
Type this:
echo 'ssh-copy-id -i /tmp/jen67/controller/jenkins_agent.pub jenkins@agent01'
You will see:
ssh-copy-id -i /tmp/jen67/controller/jenkins_agent.pub jenkins@agent01
What it means: Copy tip.
Example 12: d3
Type this:
printf '%s\n' 'In Jenkins: Manage Jenkins -> Credentials -> Add SSH Username with private key' 'ID: agent-ssh' > /tmp/jen67/controller/CRED.txt && cat /tmp/jen67/controller/CRED.txt
You will see:
ID: agent-ssh
What it means: Credential.
Step 5: Create agent01
Why: Node with docker label. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: node form tips. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 13: e1
Type this:
printf '%s\n' 'Name: agent01' 'Remote root: /home/jenkins/agent' 'Labels: jdk17 docker' 'Launch: SSH' 'Host: 10.0.3.11' 'Credential: agent-ssh' > /tmp/jen67/agents/agent01.txt && cat /tmp/jen67/agents/agent01.txt
You will see:
Labels: jdk17 docker
What it means: agent01.
Example 14: e2
Type this:
echo 'Availability: Keep this agent online'
You will see:
Availability: Keep this agent online
What it means: Online.
Example 15: e3
Type this:
echo 'Verify: Manage Nodes shows agent01 as Connected'
You will see:
Verify: Manage Nodes shows agent01 as Connected
What it means: Check.
Step 6: Create agent02
Why: Node with maven label. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: second agent. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 16: f1
Type this:
printf '%s\n' 'Name: agent02' 'Remote root: /home/jenkins/agent' 'Labels: jdk17 maven' 'Launch: SSH' 'Host: 10.0.3.12' 'Credential: agent-ssh' > /tmp/jen67/agents/agent02.txt && cat /tmp/jen67/agents/agent02.txt
You will see:
Labels: jdk17 maven
What it means: agent02.
Example 17: f2
Type this:
echo 'Same JDK major on every agent that shares a label'
You will see:
Same JDK major on every agent that shares a label
What it means: Consistency.
Example 18: f3
Type this:
echo 'Do not install build tools on the controller'
You will see:
Do not install build tools on the controller
What it means: Thin controller.
4. Automate and verify
Step 7: Smoke freestyle
Why: Hello on each label. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: job tips. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 19: g1
Type this:
printf '%s\n' 'Job: smoke-agent01' 'Restrict where: agent01' 'Build step: echo hello-agent01 > hello.txt && hostname' > /tmp/jen67/jobs/smoke-agent01.txt && cat /tmp/jen67/jobs/smoke-agent01.txt
You will see:
Restrict where: agent01
What it means: Job1.
Example 20: g2
Type this:
printf '%s\n' 'Job: smoke-agent02' 'Restrict where: agent02' 'Build step: echo hello-agent02 > hello.txt && hostname' > /tmp/jen67/jobs/smoke-agent02.txt && cat /tmp/jen67/jobs/smoke-agent02.txt
You will see:
Restrict where: agent02
What it means: Job2.
Example 21: g3
Type this:
echo 'Blue ball + console shows the agent hostname = PASS'
You will see:
Blue ball + console shows the agent hostname = PASS
What it means: Pass.
Step 8: CLI tip
Why: jenkins-cli basics. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: cli jar tip. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 22: h1
Type this:
echo 'wget http://CONTROLLER:8080/jnlpJars/jenkins-cli.jar -O /tmp/jen67/jenkins-cli.jar'
You will see:
wget http://CONTROLLER:8080/jnlpJars/jenkins-cli.jar -O /tmp/jen67/jenkins-cli.jar
What it means: CLI jar.
Example 23: h2
Type this:
echo 'java -jar jenkins-cli.jar -s http://CONTROLLER:8080 -auth user:token who-am-i'
You will see:
java -jar jenkins-cli.jar -s http://CONTROLLER:8080 -auth user:token who-am-i
What it means: who-am-i.
Example 24: h3
Type this:
echo 'Prefer API tokens over passwords for CLI and scripts'
You will see:
Prefer API tokens over passwords for CLI and scripts
What it means: Token habit.
Step 9: Security basics
Why: Reverse proxy and CSRF. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: harden tips. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 25: i1
Type this:
printf '%s\n' 'Put Nginx or ALB in front of :8080' 'Enable CSRF protection (default on modern LTS)' 'Disable anonymous read if not needed' > /tmp/jen67/controller/HARDEN.txt && cat /tmp/jen67/controller/HARDEN.txt
You will see:
Enable CSRF protection (default on modern LTS)
What it means: Harden.
Example 26: i2
Type this:
echo 'Backup JENKINS_HOME before plugin experiments'
You will see:
Backup JENKINS_HOME before plugin experiments
What it means: Backup tip.
Example 27: i3
Type this:
echo 'Pin LTS; avoid weekly on production controllers'
You will see:
Pin LTS; avoid weekly on production controllers
What it means: LTS.
5. Harden and accept
Step 10: Story TCS
Why: Pune overload. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: story file. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 28: j1
Type this:
printf '%s\n' 'At TCS in Pune, every Maven job ran on the controller. Disk filled and the UI froze in release week.' 'Meera moved builds to labelled agents and kept the controller thin.' > /tmp/jen67/STORY.txt && wc -l /tmp/jen67/STORY.txt
You will see:
2 /tmp/jen67/STORY.txt
What it means: Story.
Example 29: j2
Type this:
echo 'Rough delay: about ₹12 lakh in slipped delivery that sprint'
You will see:
Rough delay: about ₹12 lakh in slipped delivery that sprint
What it means: Cost.
Example 30: j3
Type this:
echo 'Meera: PASS when both agents Connected and smoke jobs blue'
You will see:
Meera: PASS when both agents Connected and smoke jobs blue
What it means: Sign-off.
Step 11: Local proof
Why: Files ready. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: list artifacts. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 31: k1
Type this:
ls /tmp/jen67/controller /tmp/jen67/agents /tmp/jen67/jobs
You will see:
/tmp/jen67/controller:\nCRED.txt\nHARDEN.txt\nSERVICE.txt\nUNLOCK.txt\n\n/tmp/jen67/agents:\nagent01.txt\nagent02.txt\n\n/tmp/jen67/jobs:\nsmoke-agent01.txt\nsmoke-agent02.txt
What it means: Tree.
Example 32: k2
Type this:
test -f /tmp/jen67/STORY.txt && echo 'story ok'
You will see:
story ok
What it means: story.
Example 33: k3
Type this:
echo 'Next: freestyle build and test project 68'
You will see:
Next: freestyle build and test project 68
What it means: Bridge.
Step 12: Acceptance
Why: Controller thin, agents ready. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: final gates. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 34: z1
Type this:
echo 'Jenkins LTS service running'
You will see:
Jenkins LTS service running
What it means: Service.
Example 35: z2
Type this:
echo 'agent01 and agent02 Connected with labels'
You will see:
agent01 and agent02 Connected with labels
What it means: Agents.
Example 36: z3
Type this:
echo 'Two smoke jobs blue'
You will see:
Two smoke jobs blue
What it means: Jobs.
Check yourself
Q1. Who fixed TCS controller overload?
Meera
Q2. Jenkins port default?
8080
Q3. Agent connection?
SSH
Q4. Label example?
jdk17
Q5. Smoke file?
hello.txt
Q6. Keep controller thin?
yes
Friends, you installed Jenkins with two labelled agents. Did you understand? Let us try it once more. Add a third agent labelled python and prove a freestyle job lands on it.
मित्रांनो, तुम्ही दोन labelled agents सह Jenkins बसवला. python label असलेला तिसरा agent जोडा आणि freestyle job त्यावर पडते हे सिद्ध करा.
दोस्तों, आपने दो labelled agents के साथ Jenkins लगाया. python label वाला तीसरा agent जोड़ें और freestyle job उसी पर गिरे, यह साबित करें.
Lab: try at home
- Install controller packages.
- Unlock and save initialAdminPassword.
- Configure two agents.
- Run hello smoke jobs.
Recap
- Controller stays thin.
- Agents carry the tools.
- Labels target jobs.
- SSH keys beat passwords.
- Smoke every new agent.