0
0
Jenkinsdevops~30 mins

Cloud agent provisioning (EC2, Azure) in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Cloud Agent Provisioning with Jenkins on EC2 and Azure
📖 Scenario: You are setting up Jenkins to automatically provision cloud agents on AWS EC2 and Microsoft Azure. This helps Jenkins run jobs on fresh cloud machines that start when needed and stop when done, saving resources and cost.We will create a simple Jenkins pipeline script that defines the cloud agents and provisions them on demand.
🎯 Goal: Build a Jenkins pipeline script that defines cloud agents for EC2 and Azure, configures their settings, and runs a simple job on each agent.This teaches how to automate cloud agent provisioning using Jenkins declarative pipeline syntax.
📋 What You'll Learn
Create a Jenkins pipeline script with cloud agent definitions
Add configuration variables for EC2 and Azure agents
Use the agent directive to specify cloud agents
Run simple shell commands on each cloud agent
Print the output of the commands to verify provisioning
💡 Why This Matters
🌍 Real World
Automating cloud agent provisioning helps teams run CI/CD jobs on fresh cloud machines, improving scalability and cost efficiency.
💼 Career
DevOps engineers often configure Jenkins to provision and manage cloud agents on AWS and Azure for automated build and deployment pipelines.
Progress0 / 4 steps
1
Define EC2 and Azure cloud agents
Create a Jenkins pipeline script with a pipeline block. Inside agent, define two cloud agents: ec2-agent and azure-agent. Use label to name them exactly as 'ec2-agent' and 'azure-agent'.
Jenkins
Need a hint?

Use agent none at pipeline level, then define agents inside parallel stages with agent { label '...' }.

2
Add configuration variables for cloud agents
Inside the pipeline block but before stages, add an environment block. Define two variables: EC2_INSTANCE_TYPE set to 't2.micro' and AZURE_VM_SIZE set to 'Standard_B1s'.
Jenkins
Need a hint?

Use the environment block to set variables inside the pipeline block.

3
Run shell commands on each cloud agent
Inside the steps of EC2 Agent stage, add a shell command to print echo "Running on EC2 instance type: $EC2_INSTANCE_TYPE". Inside the steps of Azure Agent stage, add a shell command to print echo "Running on Azure VM size: $AZURE_VM_SIZE".
Jenkins
Need a hint?

Use sh 'echo "text"' inside steps to run shell commands on agents.

4
Print the output to verify provisioning
Add a final stage called Verify Output that runs on agent any. Inside steps, add a shell command to print echo "Cloud agents provisioning test complete". This confirms the pipeline ran successfully.
Jenkins
Need a hint?

Add a new stage with agent any and a shell command to print the confirmation message.