Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hudson*.groovy not found in jenkins

I am trying to configure jenkins job with groovy scripts, I donot know what I am doing wrong with the configuration that I could not execute even a simple groovy command like

println System.getenv("PATH")

it shows the following stack trace when the jenkins tries to build then following error is thrown

[workspace] $ groovy "C:\Program Files (x86)\Jenkins\jobs\{Project_Name}\workspace\hudson2392295018240496017.groovy" 
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: Cannot run program "groovy" (in directory "C:\Program Files (x86)\Jenkins\jobs\{Project_Name}\workspace"): CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at hudson.Proc$LocalProc.<init>(Proc.java:244)
    at hudson.Proc$LocalProc.<init>(Proc.java:216)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:780)
    at hudson.Launcher$ProcStarter.start(Launcher.java:360)
    at hudson.Launcher$ProcStarter.join(Launcher.java:367)
    at hudson.plugins.groovy.Groovy.perform(Groovy.java:110)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:772)
    at hudson.model.Build$BuildExecution.build(Build.java:199)
    at hudson.model.Build$BuildExecution.doRun(Build.java:160)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:535)
    at hudson.model.Run.execute(Run.java:1732)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:234)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 16 more
Build step 'Execute Groovy script' marked build as failure
Finished: FAILURE

I am using default groovy version in jenkins configuration and have installed the jenkins plugins for groovy.

I am new to both jenkins and groovy. Thanks in advance.

like image 275
Himanshu Avatar asked Sep 26 '14 13:09

Himanshu


People also ask

Is Groovy needed for Jenkins?

Groovy scripts are not necessarily suitable for all users, so Jenkins created the Declarative pipeline. The Declarative Pipeline syntax is more stringent. It needs to use Jenkins' predefined DSL structure, which provides a simpler and more assertive syntax for writing Jenkins pipelines.

How Groovy is used in Jenkins?

Groovy is a very powerful language which offers the ability to do practically anything Java can do including: Create sub-processes and execute arbitrary commands on the Jenkins controller and agents. It can even read files in which the Jenkins controller has access to on the host (like /etc/passwd )

How do I run a Groovy script in Jenkins pipeline?

In Jenkinsfile, simply use load step to load the Groovy script. After the Groovy script is loaded, the functions insides can be used where it can be referenced, as shown above.


1 Answers

You need to have an install of Groovy which your Jenkins can see - which is the default option

Alternatively, you can add one in the global config

enter image description here

which can then be used in the build step

enter image description here

Started by user anonymous
Building in workspace /Users/xxxxxx/.jenkins/jobs/gr/workspace
[workspace] $ groovy /Users/xxxxx/.jenkins/jobs/gr/workspace/hudson5419917819864291744.groovy
build
/Users/xxxxxx/perl5/perlbrew/bin:/Users/xxxxx/perl5/perlbrew/perls/perl-5.16.0/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Finished: SUCCESS
like image 112
KeepCalmAndCarryOn Avatar answered Oct 23 '22 05:10

KeepCalmAndCarryOn