📖 Scenario: You are setting up a Jenkins environment to automate software builds. Jenkins uses a master-agent architecture where the master controls the build process and agents run the build jobs.In this project, you will create a simple Jenkins pipeline script that defines the master and an agent node to run a build step.
🎯 Goal: Build a Jenkins pipeline script that specifies a master and an agent node, then runs a simple shell command on the agent.
📋 What You'll Learn
Create a Jenkins pipeline with a pipeline block
Define an agent with label linux
Add a stage named Build
Inside the stage, run a shell command echo "Building on agent"
💡 Why This Matters
🌍 Real World
Jenkins pipelines automate software builds and tests by distributing work from the master to multiple agent nodes.
💼 Career
Understanding master-agent architecture is essential for DevOps engineers to set up scalable CI/CD pipelines.
Progress0 / 4 steps
1
Create the pipeline block
Write a Jenkins pipeline script starting with pipeline {} block.
Jenkins
Hint
The pipeline block is the root of your Jenkinsfile script.
2
Add an agent with label linux
Inside the pipeline block, add an agent section with label 'linux' to specify the agent node.
Jenkins
Hint
The agent label tells Jenkins which node to run the build on.
3
Add a Build stage with a shell step
Inside the pipeline block, add a stages section with one stage named Build. Inside this stage, add a steps block that runs the shell command echo "Building on agent" using sh.
Jenkins
Hint
The sh step runs shell commands on the agent node.
4
Print the pipeline script
Print the entire Jenkins pipeline script you wrote.
Jenkins
Hint
Use println to output confirmation text.
Practice
(1/5)
1. What is the main role of the Jenkins master in the master-agent architecture?
easy
A. To run jobs on different machines
B. To control and schedule jobs
C. To store job logs only
D. To act as a backup server
Solution
Step 1: Understand the master role
The Jenkins master is responsible for controlling and scheduling jobs, meaning it decides when and where jobs run.
Step 2: Differentiate from agent role
Agents actually run the jobs on separate machines, not the master.
Final Answer:
To control and schedule jobs -> Option B
Quick Check:
Master controls jobs = B [OK]
Hint: Master schedules jobs; agents run them [OK]
Common Mistakes:
Confusing master with agent role
Thinking master runs jobs directly
Assuming master only stores logs
2. Which of the following is the correct way to define an agent in a Jenkins pipeline script?
easy
A. run agent
B. master agent
C. agent any
D. node master
Solution
Step 1: Recall Jenkins pipeline syntax
In Jenkins declarative pipeline, agent any means the job can run on any available agent.
Step 2: Check other options
Options like master agent, run agent, and node master are not valid syntax for defining agents.
Final Answer:
agent any -> Option C
Quick Check:
Correct agent syntax = A [OK]
Hint: Use 'agent any' to run on any available agent [OK]
Common Mistakes:
Using invalid keywords like 'master agent'
Confusing 'node' with 'agent'
Writing 'run agent' which is not valid
3. Given this Jenkins pipeline snippet, what will happen?