Day 28 - Jenkins Agents

Day 28 - Jenkins Agents

The Jenkins architecture is designed for distributed build environments. It allows us to use different environments for each build project balancing the workload among multiple agents running jobs in parallel.

The Jenkins controller is the original node in the Jenkins installation. The Jenkins controller administers the Jenkins agents and orchestrates their work, including scheduling jobs on agents and monitoring agents.

What is the Jenkins Master (Server)?

Jenkins’s server or master node holds all key configurations. Jenkins master server is like a control server that orchestrates all the workflow defined in the pipelines. For example, scheduling a job, monitoring the jobs, etc.

This node manages other nodes running the Jenkins Agent.

What is a Jenkins Agents (Formerly Slave)?

An agent is typically a machine, or container, which connects to a Jenkins controller and executes tasks when directed by the controller.

Agents may be connected to the Jenkins controller using either local or cloud computers. It requires a Java installation and a network connection to the Jenkins controller.

Jenkins Agent is a worker node that executes the tasks and builds assigned by the Jenkins Master. It works as a distributed system where the Jenkins Master assigns tasks to Jenkins Agents, which then execute the tasks on the machines they are running on.

When you create a Jenkins job, you have to assign an agent to it. Every agent has a label as a unique identifier. The agent section in the Pipeline specifies where the entire Pipeline, or a specific stage, will execute in the Jenkins environment.

What is a Jenkins Node?

A Jenkins node is an umbrella term for Agents and Controllers, regardless of their actual roles. A node is a machine on which you can build projects and pipelines. Jenkins automatically monitors the health of all connected nodes, and if metrics go below a threshold, it takes the node offline.

Getting Started With Jenkins Master and Agent Instances

  1. Launch an EC2 instance, named "Jenkins-master".

  2. Connect it with terminal.

  3. Install Java and Jenkins on the master instance. Refer this Installation Of Java and Jenkins.

  4. Now login to Jenkins using <Your_Public_IP:8080> via browser. Add 8080 to security group under inbound rules in your instance using the AWS console.
    You will see the below page.

    You can find the Admin password on the location given in the above snapshot.

  5. You need to setup Jenkins here, Refer to Setting up Jenkins.

  6. Launch another instance, named "Jenkins-agent".

  7. Connect it with terminal and install Java on this terminal.

  8. Now Go to Your Jenkins and click on "Manage Jenkins".

  9. Click on "Security"

  10. Under Security, Go to "Agents" and in TCP port, Select "Random" and save the configuration.

  11. Now, In "Manage Jenkins", Go to "Nodes".

  12. Click on "New Node".

  13. Now give the name of your node and select "Permanent Agent".

  14. Now, configure your node. Give the Remote root directory where your node will get launch and will do the tasks and leave all the settings as default and click on "Save".

  15. You can see, we have our node and it is offline as of now.

  16. Click on your agent, you will see the below page.

  17. On Jenkins-agent instance just paste the commands given in the above screenshot a per you choice. You can choose any of the above according to your OS.

  18. I have got the above error, while connecting as the port was not specified on the master instance. So, I have added the port in the security group.

  19. Then run the command again, it worked.]

Creating Job on Jenkins with Node Configured in it

  1. Create a new Jenkins freestyle project named "Django-todo"

  2. Repo link I have used: django-todo-cicd.

  3. Configure the project. Under "General Settings" > Select "Restrict where this project can be run" > Select the "Node".

  4. In the Source Code Management section > Select Git > Enter the GitHub Repository Link and the branch name.

  5. In the Build Steps section > Select Add Build Steps > Select Execute Shell > And type the commands required for your activity. Click on Save.

      docker build -t todoapp .
      docker run -d --name django-todo-app -p 8000:8000 todoapp:latest
    
  6. Before building the project, see if Docker is installed on your Jenkins-agent or not. If not then install it.

  7. Build your project.

  8. You can see, the Job is running on "Agent-1" which is our node.

  9. Once the project is built successfully, a green tick can be observed beside the build number.

  10. And for the detailed output, you can go to console output of your build.

Now, for seeing if your application is accessible or not use your <Public_IP_jenkins_agent:Port> in browser. Remember to add port in the Jenkins-agent instance.

Conclusion

In conclusion, Jenkins master and slave nodes form a crucial architecture for continuous integration and delivery (CI/CD) in software development.

The master node serves as the central control hub, managing and coordinating tasks, while the slave nodes execute these tasks in a distributed fashion. This setup enhances scalability, resource utilization, and overall efficiency in the development pipeline.

By delegating workload to multiple slave nodes, Jenkins optimizes build and deployment processes, enabling faster and more streamlined software delivery. The master-slave configuration in Jenkins promotes a robust and adaptable CI/CD ecosystem, essential for modern software development practices.

Hope you find it helpful🤞 So I encourage you to try this on your own and let me know in the comment section👇 about your learning experience.✨

👆The information presented above is based on my interpretation. Suggestions are always welcome.😊

~Smriti Sharma✌