Skip to main content

Introduction

The Jenkins Script Console enables administrators to execute Groovy scripts directly on the controller or any connected agent. This powerful interface is ideal for debugging, configuration, and maintenance tasks.
The Script Console provides unrestricted control over your Jenkins instance. Only trusted users with admin privileges should have access.

Accessing the Script Console

You can open the Script Console in two ways:
  1. From the Jenkins dashboard:
    • Go to Manage JenkinsScript Console.
The image shows a Jenkins dashboard with a dropdown menu open, displaying various options like "New Item," "Build History," and "Script Console." The background lists different Jenkins jobs with their statuses and execution times.
  1. From Manage Nodes:
    • Select the Built-In Node and click Script Console.

Basic Groovy Scripts

Most common Jenkins classes are pre-imported, so you can start scripting immediately:

Printing the Jenkins Version

Explicitly import the Jenkins class to fetch the current version:

Retrieving Job Details

This script iterates through all jobs and prints key attributes:

Leveraging Community Scripts

jenkinsci/jenkins-scripts

The jenkinsci/jenkins-scripts repository provides numerous utilities. For example, count executors on each node:
The image shows a GitHub repository page for "jenkinsci/jenkins-scripts" with a list of Groovy script files and their last commit messages.
Output example:

samrocketman/jenkins-script-console-scripts

Another valuable collection is samrocketman/jenkins-script-console-scripts. The Jenkins stats script gathers metrics on jobs, users, builds, and more:
This image shows a GitHub repository page for "jenkins-script-console-scripts" by "samrocketman," featuring a list of files and directories related to Jenkins script console scripts. The repository is public and includes details like the number of stars, forks, and commits.
Always review third-party scripts before executing to ensure they’re safe and free of malicious code.

Disabling the Jenkins CLI

To disable CLI access (both TCP and /cli URL), run the following Groovy script:

Conclusion

The Script Console is a powerful Jenkins feature for automation, diagnostics, and configuration. Always proceed with caution and restrict console access to trusted administrators.

Watch Video