When you are after installation of groovy plugin:

You probably sooner or later will try to execute the groovy script. Hire I’m not talking about Executing System Groovy Script, this usually is working out of the box, but when You try to Execute Groovy Script

You may experience following error:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | [Test] $ groovy /var/jenkins_home/workspace /Test/hudson481621137087598172.groovy FATAL: command execution failed java.io.IOException: Cannot run program "groovy" (in directory "/var/jenkins_home/workspace/Test"): error=2, No such file or directory at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) at hudson.Proc$LocalProc.<init>(Proc.java:249) at hudson.Proc$LocalProc.<init>(Proc.java:218) at hudson.Launcher$LocalLauncher.launch(Launcher.java:935) at hudson.Launcher$ProcStarter.start(Launcher.java:454) at hudson.Launcher$ProcStarter.join(Launcher.java:465) at hudson.plugins.groovy.Groovy.perform(Groovy.java:106) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744) at hudson.model.Build$BuildExecution.build(Build.java:206) at hudson.model.Build$BuildExecution.doRun(Build.java:163) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504) at hudson.model.Run.execute(Run.java:1815) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) Caused by: java.io.IOException: error=2, No such file or directory at java.lang.UNIXProcess.forkAndExec(Native Method) at java.lang.UNIXProcess.<init>(UNIXProcess.java:247) at java.lang.ProcessImpl.start(ProcessImpl.java:134) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) ... 15 more Build step 'Execute Groovy script' marked build as failure Finished: FAILURE |
If you have this problem solution is to install groovy:
1 | sudo apt install groovy |
Then You should check installed version
1 | groovy -version |
I had not satisfying result:
1 2 | mbahojlo@mbahojlocomp:~$ groovy -version groovy: JAVA_HOME is not defined correctly, can not execute: /usr/lib/jvm/default-java/bin/java |
To fix this just check where your Java is, on Ubuntu it should be:

So set the JAVA_HOME:
Open /etc/environment in any text editor add the following line:
1 | JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64" |
(java path could be different)
Use source to load the variables, by running this command:
1 | source /etc/environment |
Then check the variable, by running this command:
1 | echo $JAVA_HOME |
And then again check groovy version :
1 2 | groovy -version Groovy Version: 2.4.17 JVM: 1.8.0_275 Vendor: Private Build OS: Linux |
So after this process You need to add path to your groovy binaries in Jenkins -> Manage Jenkins -> Global Tool Configuration. Once you install groovy on your machine provide path to it’s installation folder. For example on my machine it’s like shown on the picture below
