Step-by-Step Instructions for Establishing Jenkins with Agents for Effortless CI/CD ๐
Introduction:
In the dynamic world of DevOps, continuous integration and continuous deployment (CI/CD) are indispensable. Jenkins, a powerful automation server, plays a pivotal role in facilitating these processes. To enhance its capabilities, setting up Jenkins with agents becomes essential. In this blog post, we'll guide you through the process of creating a Jenkins master server and connecting it with agents on separate EC2 instances.
Prerequisites:
Before we dive into the setup, ensure you have two EC2 instances โ one for the Jenkins master server and another for the agent. Here are the prerequisites for each:
Jenkins Master Server:
Java: Ensure Java is installed on the Jenkins master server.
Jenkins: Install Jenkins on the master server by following the official installation instructions.
Agent Server:
Java: Install Java on the agent server.
Additional Tools: Install any project-specific tools required for the agent on the server, such as Docker, Docker Compose, Trivy, etc.
SSH Connection Setup:
Generate an Ed25519 SSH key pair on the master server using
ssh-keygen -t ed25519
. Copy the public key.On the agent server, navigate to
~/.ssh/
and edit theauthorized_keys
file usingsudo vim authorized_keys
. Paste the copied public key.Create SSH credentials in Jenkins:
Navigate to Dashboard > Manage Jenkins > Credentials > System > Global credentials (unrestricted).
Add new credentials of type "SSH Username with private key."
Enter the username (e.g., ubuntu) and add the private key content.
Creating Jenkins Node:
Go to Dashboard > Manage Jenkins > Nodes > New Node.
Set the Node Name (e.g., dev-server) and choose "Permanent Agent."
Provide a description, which helps identify the purpose or characteristics of the node.
Set the remote root directory (e.g., /home/ubuntu/dev-workspace), indicating the location where the agent thinks it will store its workspace files.
Labels:
Labels are crucial for identifying and categorizing agents. They act as tags that help Jenkins understand which agent to assign a specific job or pipeline.
For example, you might label an agent as 'dev-agent' to signify that it's suitable for development tasks.
Choose the option to "Only build jobs with label expressions matching this node."
For Launch Method, select "Launch agents via SSH."
Enter the public IP of the agent server and choose "Non-verifying Verification Strategy" for the Host Key Verification Strategy.
Keep other configurations as default and save the node.
Launch the agent, and monitor the console output for any errors or success messages.
Sample Pipeline Code:
pipeline {
agent {label: 'dev-agent'}
stages {
stage("Code") {
steps {
echo 'Something here'
}
}
}
}
Special Thanks: ๐
A big shoutout and heartfelt thanks to Train With Shubham (TWS) or DevOps wale bhaiya for their invaluable contributions. ๐
Conclusion:
Setting up Jenkins with agents establishes a robust CI/CD foundation. This ensures efficient and scalable automation, crucial for modern software development. ๐โจ