What is Node in Jenkins: Explanation and Usage
node is a machine or environment where Jenkins runs tasks or jobs. It can be the main Jenkins server (called the controller) or any other machine (called an agent) connected to Jenkins to perform work.How It Works
Think of Jenkins as a manager who assigns tasks to workers. The node is like a worker machine where these tasks get done. The main Jenkins server is one node, often called the controller, which controls the process and schedules jobs.
Other nodes, called agents, are additional machines connected to Jenkins. They help by running jobs in parallel or on different environments, like Windows or Linux. This setup lets Jenkins spread work across many machines, making automation faster and more flexible.
Example
This example shows how to define a node block in a Jenkins Pipeline script to run a job on a specific node labeled 'linux-agent'.
pipeline {
agent { label 'linux-agent' }
stages {
stage('Build') {
steps {
echo 'Building on the linux-agent node'
}
}
}
}When to Use
Use nodes when you want to run Jenkins jobs on different machines or environments. For example, if you need to test software on Windows and Linux, you can set up nodes for each OS. Jenkins will send jobs to the right node based on labels.
Nodes are also useful to balance workload. If your main server is busy, agents can run jobs to keep things moving smoothly. This helps in large projects with many builds or tests running at the same time.
Key Points
- A
nodeis any machine Jenkins uses to run jobs. - The main Jenkins server is a node called the controller.
- Additional nodes (agents) help run jobs in parallel or on different platforms.
- Nodes are identified by labels to target specific environments.
- Using nodes improves speed and flexibility of automation.