在詹金斯工作中执行Groovy脚本

时间:2018-10-18 11:40:20

标签: jenkins jenkins-groovy

我在詹金斯(Jenkins)还很陌生,我正在尝试在詹金斯(Jenkins)运行groovy脚本'println“ hello world”'。但是我遇到了错误。

  [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

我找到了一些解决方法Run groovy scripts in Jenkins,但不确定如何在我的情况下使用。

2 个答案:

答案 0 :(得分:0)

您需要在Jenkins-> Manage Jenkins->全局工具配置中向您的Groovy二进制文件添加路径。在计算机上安装groovy之后,请提供其安装文件夹的路径。例如在我的机器上,如下图所示: Groovy installations

答案 1 :(得分:0)

在Jenkins中检查全局工具配置之前,您可以尝试安装/更新Homebrew安装并首先运行“ brew install groovy”。这将使您能够设置常规起始路径(http://macappstore.org/groovy/)。否则,Jenkins可能无法正确保存您的工具配置。

您应该设置GROOVY_HOME:

export GROOVY_HOME=/usr/local/opt/groovy/libexec