Triggering Jenkins Jobs Concurrently per Node with Parameters
In continuous integration and continuous delivery (CI/CD) pipelines, it is often required to run jobs concurrently on multiple nodes, with each node running a job instance with specific parameters. This article will cover how to trigger Jenkins jobs concurrently per node with parameters using the NodeLabel Parameter Plugin, and also provide some best practices and troubleshooting tips for using this plugin.
Installing the NodeLabel Parameter Plugin
The NodeLabel Parameter Plugin can be installed from the Jenkins Plugin Manager. To install it, follow these steps:
- Go to the Jenkins home page.
- Click on "Manage Jenkins" in the sidebar.
- Select "Manage Plugins" from the dropdown menu.
- Click on the "Available" tab.
- Search for "NodeLabel Parameter Plugin" in the search bar.
- Check the box next to the plugin name, then click on the "Install without restart" button.
Creating a Job with Parameters
To create a job that takes parameters, follow these steps:
- Go to the Jenkins home page.
- Click on "New Item" in the sidebar.
- Enter a name for the job, then select "Freestyle project" and click "OK".
- Under "General", check the box for "This project is parameterized".
- Select "String parameter" and enter "sleep" for the name. This will allow us to specify a sleep time for each job instance.
- Click on the "Add" button to add the parameter.
Configuring the Job to Run on Multiple Nodes
To configure the job to run on multiple nodes, follow these steps:
- Under "Build Triggers", check the box for "Build multiple branches simultaneously".
- Under "Node Parameters", check the box for "Node Label Parameter" and enter "JobFooRunner" for the name.
- Add a description for the parameter such as "Enter the label of the node to run the job on.".
- Click on the "Add" button to add the parameter.
Adding a Node Label to the Job Configuration
Now, we need to add a node label to the job configuration. To do this:
- Under "Restrict where this project can run", add a label expression such as "nodeA || nodeB || nodeC".
- Save the job configuration.
Triggering the Job Concurrently per Node
To trigger the job concurrently per node, follow these steps:
- Go to the job page and click on "Build with Parameters" in the sidebar.
- Enter a value for the "sleep" parameter, then enter a node label for the "JobFooRunner" parameter and click "Build".
- Repeat the previous step for each node label you want to run the job on, ensuring each job instance has a unique sleep time value.
Troubleshooting and Best Practices
Here are some troubleshooting tips and best practices for using the NodeLabel Parameter Plugin:
- Ensure that each node has a unique label.
- Use a naming convention for labels, such as "nodeA-win", "nodeB-linux".
- Use a separate parameter for each label, instead of using a single parameter with comma-separated labels.
- Ensure that the job is not limited to a single executor on each node.
- Verify that each node has sufficient resources, such as CPU, memory, and disk space, for running the job.
References
- NodeLabel Parameter Plugin documentation
- Pipeline documentation
- Multi-branch Project documentation
- Example of NodeLabel Parameter Plugin configuration
In this article, we covered how to trigger Jenkins jobs concurrently per node with parameters using the NodeLabel Parameter Plugin. We provided detailed context, subtitles, paragraphs, and code blocks to help you understand and implement the solution. We excluded page layout tags, specified types of references, and ensured that the output HTML was valid and properly formatted.