Groovy脚本无法从Jenkins DSL作业调用Slack通知参数
我第一次尝试使用Jenkins Job DSL插件来创建一些基本的工作“模板”,然后再开始更复杂的工作 Jenkins正在Windows 2012服务器上运行。Jenkins版本是1.650,我们使用的是Job DSL插件版本1.51 理想情况下,我希望对种子作业进行参数化,以便在运行时用户可以输入四项内容:作业DSL脚本位置、生成作业的名称、故障通知的空闲通道以及故障通知的电子邮件地址 前两个很好:我可以调用groovy脚本中的参数,例如,脚本理解Groovy脚本无法从Jenkins DSL作业调用Slack通知参数,groovy,slack,jenkins-job-dsl,Groovy,Slack,Jenkins Job Dsl,我第一次尝试使用Jenkins Job DSL插件来创建一些基本的工作“模板”,然后再开始更复杂的工作 Jenkins正在Windows 2012服务器上运行。Jenkins版本是1.650,我们使用的是Job DSL插件版本1.51 理想情况下,我希望对种子作业进行参数化,以便在运行时用户可以输入四项内容:作业DSL脚本位置、生成作业的名称、故障通知的空闲通道以及故障通知的电子邮件地址 前两个很好:我可以调用groovy脚本中的参数,例如,脚本理解作业(${job\u NAME}”),并使用我
作业(${job\u NAME}”)
,并使用我在运行种子作业时为作业输入的名称
然而,当我尝试用松弛通道做同样的事情时,groovy脚本似乎不想播放。请注意,如果我指定一个松弛通道,而不是尝试调用一个参数,它就可以正常工作
我的工作DSL脚本如下:
job("${JOB_NAME}") {
triggers {
cron("@daily")
}
steps {
shell("echo 'Hello World'")
}
publishers {
slackNotifier {
room("${SLACK_CHANNEL}")
notifyAborted(true)
notifyFailure(true)
notifyNotBuilt(false)
notifyUnstable(true)
notifyBackToNormal(true)
notifySuccess(false)
notifyRepeatedFailure(false)
startNotification(false)
includeTestSummary(false)
includeCustomMessage(false)
customMessage(null)
buildServerUrl(null)
sendAs(null)
commitInfoChoice('NONE')
teamDomain(null)
authToken(null)
}
}
logRotator {
numToKeep(3)
artifactNumToKeep(3)
publishers {
extendedEmail {
recipientList('me@mydomain.com')
defaultSubject('Seed job failed')
defaultContent('Something broken')
contentType('text/html')
triggers {
failure ()
fixed ()
unstable ()
stillUnstable {
subject('Subject')
content('Body')
sendTo {
developers()
requester()
culprits()
}
}
}
}
}
}
}
但启动种子作业失败,并提供以下输出:
Started by user
Building on master in workspace D:\data\jenkins\workspace\tutorial-job-dsl-2
Disk space threshold is set to :5Gb
Checking disk space Now
Total Disk Space Available is: 28Gb
Node Name: master
Running Prebuild steps
Processing DSL script jobBuilder.groovy
ERROR: (jobBuilder.groovy, line 10) No signature of method: javaposse.jobdsl.plugin.structs.DescribableContext.room() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [#dev]
Possible solutions: wait(), find(), dump(), grep(), any(), wait(long)
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: FAILURE
这是我第一次尝试用Groovy做任何事情,我确信这是一个基本错误,但我希望能得到任何帮助。Hm,这是Job DSL中的一个bug,请参阅 如果只想使用
FOO
的值,实际上不需要使用模板字符串语法“${FOO}”
。所有参数均为字符串变量,可直接使用:
job(JOB_NAME) {
// ...
publishers {
slackNotifier {
room(SLACK_CHANNEL)
notifyAborted(true)
notifyFailure(true)
notifyNotBuilt(false)
notifyUnstable(true)
notifyBackToNormal(true)
notifySuccess(false)
notifyRepeatedFailure(false)
startNotification(false)
includeTestSummary(false)
includeCustomMessage(false)
customMessage(null)
buildServerUrl(null)
sendAs(null)
commitInfoChoice('NONE')
teamDomain(null)
authToken(null)
}
}
// ...
}
此语法更简洁,不会触发错误。谢谢!我不知道为什么我在搜索时没有找到,因为这是一个非常明确的解释。不管怎样,它现在可以工作了,所以感谢您的帮助。我应该澄清一下-感谢您指出了这个错误以及字符串变量可以直接使用的事实。这个错误已经在Jobs DSL插件1.53及更高版本中修复: