How to add node & distribute builds in jenkins ?
Introduction
[edit]Jenkins, an open-source automation server, facilitates continuous integration and delivery of software projects. Adding a node to Jenkins allows for distributed builds, optimizing workload distribution. This guide outlines the steps to launch an EC2 instance as a Jenkins node, configure it, and delegate jobs to it.
Prerequisites
[edit]1. Access to AWS console.
2. Knowledge of launching EC2 instances.
3. SSH keypair for accessing the EC2 instance.
4. Understanding of Jenkins and basic server administration.
Step-by-Step Guide
[edit]Step 1: Launch New EC2 Instance for Jenkins Node:
1. Log in to AWS console.
2. Launch an Ubuntu EC2 instance.
3. Ensure it's launched in the same VPC as the Jenkins master.
4. Keep SSH key for accessing the instance.
Step 2: Requirement for Jenkins Node:
1. Ensure Java is installed on the EC2 instance.
2. Have the SSH keypair for Jenkins node.
Step 3: Java Installation on Jenkins Node Machine:
1. SSH into the EC2 instance.
2. Install Java using apt-get:
sudo apt-get update
sudo apt-get install default-jre
Step 4: Install Dependencies:
If required by the build, install additional dependencies on the Jenkins node machine (e.g., Python, Node.js).
Step 5: Adding Node to Master Jenkins:
1. Log in to Jenkins master node.
2. Navigate to "Manage Jenkins" > "Manage Credentials".
3. Add SSH credentials:
- Kind: SSH Username with private key.
- ID: jenkins.
- Username: jenkins.
- Private Key: Enter directly or specify the path.
- Passphrase: If applicable.
Step 6: Setup Agent:
1. Go to Jenkins dashboard.
2. Navigate to "Manage Jenkins" > "Manage Nodes and Clouds".
3. Configure the agent:
- Remote root directory: /home/ubuntu.
- Label: Agent1 (or your preferred label).
- Launch method: Launch agents by SSH.
- Host: Node IP Address.
- Credentials: Select the SSH credentials created earlier.
- Host Key verification Strategy: (Set as per your security requirements).
Step 7: Save Configuration:
1. Press the Save button.
2. The agent will be registered but offline initially.
Step 8: Delegating Jobs to Agent:
1. Log in to Jenkins.
2. Under job configuration, go to "General".
3. Click on "Restrict where this project can be run" and specify the label of the agent.
Conclusion
[edit]By following these steps, you can effectively add a Jenkins node in AWS EC2, enabling distributed builds and optimizing resource utilization in your Jenkins environment. This setup enhances the scalability and efficiency of your continuous integration and delivery processes.