Certified Jenkins Engineer

Jenkins Administration and Monitoring Part 1

Demo Job Restrictions

In this tutorial, you’ll learn how to use the Job Restrictions plugin in Jenkins to control which jobs can run on specific nodes. By leveraging job names, users, and logical operators, you can enforce security policies and prevent unintended builds.

Table of Contents

  1. Install the Job Restrictions Plugin
  2. Configure Node-Level Restrictions
    2.1 Navigate to the Built-In Node
    2.2 Enable Job Restrictions
  3. Test the Restriction
    3.1 Building an Unmatched Job
    3.2 Creating a Matching Job
  4. Add User-Based Restrictions
  5. Links and References

1. Install the Job Restrictions Plugin

  1. Go to Manage JenkinsManage Plugins.
  2. Under the Available tab, search for Job Restrictions.
  3. Select the plugin and click Install without restart.
  4. Once the installation completes, choose Restart Jenkins when installation is complete and no jobs are running.

The image shows a Jenkins interface displaying the download progress of plugins, with some tasks marked as "Success" and others as "Pending." It includes options to go back to the top page and restart Jenkins after installation.

Note

Ensure your Jenkins instance is at least version 2.387 or higher for full compatibility with the Job Restrictions plugin.

After Jenkins restarts, the plugin is ready for configuration.


2. Configure Node-Level Restrictions

2.1 Navigate to the Built-In Node

  1. From the Jenkins dashboard, click Manage JenkinsManage Nodes and Clouds.
  2. Select the built-in node (often labeled “built-in”).

The image shows a Jenkins dashboard displaying node information, including architecture, clock difference, and disk space details. It also indicates the build queue and executor status, with options to add a new node or configure monitors.

2.2 Enable Job Restrictions

  1. Click Configure on the built-in node.
  2. Scroll to Node Properties and check Job Restrictions.
  3. Click Add and select Regular Expression — Job Name.
  4. Enter a regex pattern that matches the jobs you want to allow. For example:
^Dasher_.*

The image shows a Jenkins configuration screen for a built-in node, with options for labels, usage, and node properties, including job restrictions using a regular expression.

Use Add again to combine rules with AND, OR, or NOT logic.

Common Restriction Types

Restriction TypePurposeExample Pattern
Regular Expression — Job NamePermit jobs matching a name pattern^Dasher_.*
Started by UserAllow builds initiated by specific usersEmma
Parameterized JobRestrict based on parameter valuesenv=production

3. Test the Restriction

3.1 Building an Unmatched Job

Attempt to build a job that does not match your regex—for example, npm-version-test. It will stay in the queue as Pending.

The image shows a Jenkins dashboard for a project named "npm-version-test," displaying build status and history, with the last build occurring 9 days ago. The interface includes options like "Build Now," "Configure," and "Open Blue Ocean."

Warning

Jobs that don’t meet any restriction rules will remain queued indefinitely. Monitor the queue to avoid resource bottlenecks.

3.2 Creating a Matching Job

  1. From the dashboard, click New Item.

  2. Enter Dasher_testJob and select Freestyle project.

  3. In Build steps, add a shell step:

    echo "Hello"
    
  4. Click Save, then Build Now. This job matches the pattern and will execute.

The image shows a Jenkins dashboard for a job named "Dasher_testJob," displaying build status and permalinks for recent builds. The interface includes options like "Build Now," "Configure," and "Open Blue Ocean."


4. Add User-Based Restrictions

To grant specific users the ability to run any job on this node:

  1. Navigate back to Manage JenkinsManage Nodes and Cloudsbuilt-in nodeConfigure.
  2. Under Job Restrictions, click AddStarted by User.
  3. Enter the username (e.g., Emma).
  4. Set the logical operator to OR so that jobs match either the regex rule or the user rule.
  5. Click Save.

The image shows a configuration screen from Jenkins, where job restrictions are being set using a regular expression for job names and a user list.

Now, user Emma can trigger any job on this node, while all other users must use the Dasher_ prefix.


With regex-based rules, user filters, and logical operators, you can precisely control job execution across your Jenkins nodes.

Watch Video

Watch video content

Previous
Demo Access Control for Builds