FoxuTech

How to run groovy script in Jenkins

How to run groovy script in Jenkins

After setup the master-slave and own private docker registry(cloud), now we would like to discuss about how to run the groovy script in Jenkins. Before we start, lets know some information about groovy.

What is a Groovy Script?

Apache Groovy is an Object-oriented programming language used for Java platform. This dynamic language has many features which are like Python, Ruby. It can be used as a scripting language for the Java platform.

It is almost like a super version of Java which offers Java’s enterprise capabilities. It also offers many productivity features like DSL support, closures, and dynamic typing. Unlike some other languages, it is designed as a companion, not a replacement for Java.

Groovy source code gets compiled in Java Bytecode, so it can run on any platform if JRE is installed on that operating system. Groovy also performs a lot of tasks behind the scene that makes it more agile and dynamic.

Why Groovy?

Here, are major reasons why you should use Groovy-

Features of Groovy

Cons of using Groovy

To know more: http://groovy-lang.org/

Here are the List of way using you can apply groovy code in Jenkins

Method -1: Groovy plugin
This plugin adds the ability to directly execute Groovy code.

More infohttps://wiki.jenkins.io/display/JENKINS/Groovy+plugin

Method -2: Jenkins script console
The inbuilt script console is a very useful and powerful Jenkins extension and ideally suits certain types of tasks. This is simple but powerful built-in web console allows you to run Groovy scripts on your Jenkins instance (or its slave nodes) from directly within the user interface and is installed as standard.

To access the console, either navigate to Manage Jenkins and then select Script Console, or simply append /script to your Jenkins host and port, like this for example: http://jenkins-IP:8080/script
Running Script Console on the master
This feature can be accessed from “Manage Jenkins” > “Script Console”. Or visit the sub-URL /script on your Jenkins instance.

Running Script Console on agents
Visit “Manage Jenkins” > “Manage Nodes”. Select any node to view the status page. In the menu on the left, a menu item is available to open a “Script Console” on that specific agent.

More infohttps://wiki.jenkins.io/display/JENKINS/Jenkins+Script+Console

Method -3: Scriptler Plugins
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.

Note: The current version of this plugin may not be safe to use. Please review the warnings before use.

More Infohttps://wiki.jenkins.io/display/JENKINS/Scriptler+Plugin

Exit mobile version