在Jenkins中,我尝试使用Groovy脚本将参数传递到构建管道的下游作业。在我的第一份工作中,我添加了一个Build步骤“Execute Groovy Script”并将内容添加到Groovy命令中:
import hudson.model.*
import hudson.util.*
def thr = Thread.currentThread()
def build = thr?.executable
printf "Setting UPSTREAM_ID as "+ build.getEnvVars()['BUILD_ID'] +"\n" ;
build.addAction(new ParametersAction(new StringParameterValue('UPSTREAM_ID', build.getEnvVars()['BUILD_ID'])))
我得到了输出:
[workspace] $ C:\Progra~1\Groovy\Groovy-1.5.8\bin\groovy.exe d:\JenkinsAT\jobs\Test_Job\workspace\hudson8779135058472653024.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, D:\JenkinsAT\jobs\Test_Job\workspace\hudson8779135058472653024.groovy: 6: unable to resolve class ParametersAction
@ line 6, column 17.
build.addAction(new ParametersAction(new StringParameterValue('SVN_UPSTREAM', build.getEnvVars()['BUILD_ID'])))
^
D:\JenkinsAT\jobs\Test_Job\workspace\hudson8779135058472653024.groovy: 6: unable to resolve class StringParameterValue
@ line 6, column 38.
build.addAction(new ParametersAction(new StringParameterValue('SVN_UPSTREAM', build.getEnvVars()['BUILD_ID'])))
^
2 errors
我在我的机器上安装了Groovy 1.5.8,我的Jenkins版本是1.519。我在这里做错了什么。
答案 0 :(得分:6)
通过将Jenkins-core.jar放入groovy lib目录并将Build类型更改为Execute system Groovy Script