Jenkins Script Console

Skip to end of metadata
Go to start of metadata

Jenkins Script Console

Jenkins features a nice Groovy script console which allows to run arbitrary scripts on the Jenkins server or on slave nodes. This feature can be accessed from the "manage Jenkins" link, typically at your http://server/jenkins/script.

Shortcut key on script console to submit

You can submit a script without mouse. Jenkins has a shortcut key which enables to submit with keyboard.

  • Windows / Linux : Ctrl + Enter
  • Mac : Command + Enter

Remote access

User can execute groovy scripts remotely sending post request to /script/ url or /scriptText/ to have response returned without the html wrapping.

$ curl -d "script=<your_script_here>" http://jenkins/script
$ # or
$ curl -d "script=<your_script_here>" http://jenkins/scriptText

Also, Jenkins CLI offers the possibility to execute groovy scripts remotely using groovy command or execute groovy interactivelly via groovysh. However, once again curl can be used to execute groovy scripts by making use of bash Command Substitution. In the following example somescript.groovy is a groovy script in the current working directory.

$ curl --data-urlencode "script=$(<./somescript.groovy)" http://jenkins/scriptText

If security is configured in Jenkins, then curl can be provided options to authenticate using the curl --user option.

$ curl --user 'username:password' --data-urlencode "script=$(<./somescript.groovy)" http://jenkins/scriptText

Sample Groovy scripts

Browse all Scriptler Plugin Groovy Scripts:

please share your scripts with the Scriptler Plugin

Some scripts at

More Scripts available at Scriptler Web 

Write Groovy scripts for Jenkins with Code completion - The gist of this is to create a Maven project within your IDE and to depend on org.jenkins-ci.main:jenkins-core (and any other plugins that you expect present). You can then write a Groovy script with code completion of Jenkins API objects and methods.

Plugins enabling Groovy usage

Page: Config File Provider Plugin — Adds the ability to provide configuration files (i.e., settings.xml for maven, XML, groovy, custom files, etc.) loaded through the Jenkins UI which will be copied to the job's workspace.
Page: Global Post Script Plugin — Execute a global configured groovy/python script after each build of each job managed by the Jenkins.
Page: Groovy plugin — This plugin adds the ability to directly execute Groovy code.
Page: Groovy Postbuild Plugin — This plugin executes a groovy script in the Jenkins JVM. Typically, the script checks some conditions and changes accordingly the build result, puts badges next to the build in the build history and/or displays information on the build summary page.
Page: Groovy Remote Control Plugin — This plugin provides Groovy Remote Control's receiver, and allows to control external application from Jenkins.
Page: Matrix Groovy Execution Strategy Plugin — A plugin to decide the execution order and valid combinations of matrix projects.
Page: Scriptler Plugin — Scriptler allows you to store/edit groovy scripts and execute it on any of the slaves/nodes... no need to copy/paste groovy code anymore.
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Add Comment