📖 Scenario: You are setting up a Jenkins server to run automated jobs. Jenkins uses agents (also called nodes) to run these jobs. There are two main types of agents: permanent agents that are always available, and cloud agents that start on demand in the cloud.Understanding how to configure these agents helps you manage your build resources efficiently.
🎯 Goal: Learn to create a permanent Jenkins agent configuration and a cloud agent configuration using Jenkins pipeline syntax. You will define the agents and then run a simple job on each type.
📋 What You'll Learn
Create a permanent agent configuration in Jenkins pipeline
Create a cloud agent configuration in Jenkins pipeline
Use the agent directive correctly for both types
Run a simple shell command on each agent to verify setup
💡 Why This Matters
🌍 Real World
In real Jenkins setups, permanent agents are often physical or virtual machines always connected to Jenkins. Cloud agents are created on demand in cloud platforms like AWS or Azure to save resources.
💼 Career
Knowing how to configure different agent types helps DevOps engineers optimize build times and resource usage in continuous integration and delivery pipelines.
Progress0 / 4 steps
1
Create a permanent agent configuration
Write a Jenkins pipeline script that uses a permanent agent labeled permanent-agent. Inside the stage named Build, run the shell command echo "Running on permanent agent".
Jenkins
Hint
Use agent { label 'permanent-agent' } to specify the permanent agent.
Use sh 'echo "Running on permanent agent"' inside the steps block.
2
Add a cloud agent configuration variable
Add a variable called cloudAgentLabel and set it to the string 'cloud-agent' at the top of the Jenkins pipeline script.
Jenkins
Hint
Define cloudAgentLabel as 'cloud-agent' before the pipeline block.
3
Add a stage to run on the cloud agent
Add a new stage named Test on Cloud Agent inside the stages block. Use the agent directive with the label set to the variable cloudAgentLabel. Inside the steps, run the shell command echo "Running on cloud agent".
Jenkins
Hint
Inside stages, add a new stage with agent { label cloudAgentLabel } and the shell command inside steps.
4
Print confirmation messages for both agents
Add a post block inside the pipeline that runs echo "Pipeline completed successfully" in the always section.
Jenkins
Hint
Use a post block with always to print the confirmation message.
Practice
(1/5)
1. What is a key characteristic of a permanent agent in Jenkins?
easy
A. It runs only on cloud platforms like AWS or Azure.
B. It is always connected and ready to run jobs.
C. It starts only when a job is triggered and stops afterward.
D. It automatically scales based on job demand.
Solution
Step 1: Understand permanent agent behavior
Permanent agents are set up to be always online and ready to accept jobs without delay.
Step 2: Compare with cloud agents
Cloud agents start and stop dynamically, unlike permanent agents which stay connected.
Final Answer:
It is always connected and ready to run jobs. -> Option B
Hint: Label 'cloud' usually means dynamic cloud agent [OK]
Common Mistakes:
Assuming label 'cloud' means permanent agent
Thinking label usage causes failure
Assuming master node runs all jobs
4. You configured a cloud agent in Jenkins, but jobs never run on it and stay queued. What is the most likely cause?
medium
A. The cloud agent label is missing or mismatched in the job configuration.
B. The permanent agent is offline, so cloud agents cannot start.
C. The Jenkins master node is overloaded and blocking all agents.
D. The cloud agent plugin is not installed, causing syntax errors.
Solution
Step 1: Check label matching
Jobs must specify the correct label matching the cloud agent to run on it.
Step 2: Understand job-agent assignment
If labels don't match, Jenkins queues jobs waiting for suitable agents.
Final Answer:
The cloud agent label is missing or mismatched in the job configuration. -> Option A
Quick Check:
Label mismatch causes jobs to queue [OK]
Hint: Always match job label with agent label [OK]
Common Mistakes:
Assuming permanent agent status affects cloud agents
Blaming Jenkins master overload without evidence
Confusing plugin absence with job queuing
5. You want to optimize Jenkins to save resources by using cloud agents for most jobs but keep a permanent agent for critical builds. How should you configure labels and agents?
hard
A. Assign label 'critical' to the permanent agent and 'cloud' to cloud agents; assign jobs accordingly.
B. Use only permanent agents with label 'all' and avoid cloud agents to reduce complexity.
C. Assign all jobs to label 'cloud' and disable the permanent agent to save resources.
D. Configure cloud agents without labels and assign all jobs to the permanent agent.
Solution
Step 1: Separate job types by labels
Use distinct labels like 'critical' for permanent agent and 'cloud' for cloud agents to control job assignment.
Step 2: Assign jobs to matching labels
Critical builds use the permanent agent with 'critical' label; other jobs use cloud agents with 'cloud' label.
Final Answer:
Assign label 'critical' to the permanent agent and 'cloud' to cloud agents; assign jobs accordingly. -> Option A
Quick Check:
Use labels to separate permanent and cloud jobs [OK]
Hint: Label agents and jobs to control resource use [OK]
Common Mistakes:
Using only one label for all agents
Disabling permanent agent when critical builds exist
Not assigning labels to cloud agents
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.