jenkinsgroovyjenkins-groovy

executing job disabling through groovy


I have the following grrovy script that works perfectly fine in jenkins 2.249.3

import jenkins.model.Jenkins
Jenkins.instance.getItem("JobToBeDisabled").disable()

Whereas, when the same tried on jenkins 2.452.2 , I am hitting the error.

Building in workspace /var/jenkin_8080_home/jobs/JobToBeDisabled/workspace
[workspace] $ groovy /var/jenkin_8080_home/jobs/JobToBeDisabled/workspace/hudson52599949595130215.groovy
FATAL: command execution failed
java.io.IOException: Cannot run program "groovy" (in directory "/var/jenkin_8080_home/jobs/JobToBeDisabled/workspace"): error=2, No such file or directory
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
    at hudson.Proc$LocalProc.<init>(Proc.java:252)
    at hudson.Proc$LocalProc.<init>(Proc.java:221)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:994)
    at hudson.Launcher$ProcStarter.start(Launcher.java:506)
    at hudson.Launcher$ProcStarter.join(Launcher.java:517)
    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:818)
    at hudson.model.Build$BuildExecution.build(Build.java:199)
    at hudson.model.Build$BuildExecution.doRun(Build.java:164)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:526)
    at hudson.model.Run.execute(Run.java:1894)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
    at hudson.model.ResourceController.execute(ResourceController.java:101)
    at hudson.model.Executor.run(Executor.java:442)
Caused by: java.io.IOException: error=2, No such file or directory
    at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
    at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:340)
    at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:271)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
    ... 16 more
Build step 'Execute Groovy script' marked build as failure
Finished: FAILURE

Is there some syntax or variable declaration I am missing out ?


Solution

  • The issue is fixed.

    The earlier code works as well. I mistakenly ran the code in "Execute Groovy script" instead of "Execute system Groovy script"

    Now, I will try to understand further on the difference between groovy and system groovy.