0
0
Jenkinsdevops~30 mins

Agent types (permanent, cloud) in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Jenkins Agent Types: Permanent and Cloud Agents
📖 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
Need a 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
Need a 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
Need a 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
Need a hint?

Use a post block with always to print the confirmation message.