我的减速管道有一个阶段,它使用 Webhook 向 Discord 通道发送消息。我的 Jenkins 文件中执行此操作的脚本如下。
stage('DiscordMessage') {
steps {
discordSend {
webhookURL: "https://discord.com/api/webhooks/123456789012345678/me-3_LacrufNcvKg-U",
discordSend description: 'Status of my Project',
footer: '',
image: '',
link: env.BUILD_URL,
result: currentBuild.currentResult,
scmWebUrl: '',
thumbnail: '',
title: JOB_NAME
}
}
}
jenkins 文件已签入 GIT 上的 SCM。当我在 Jenkns 上运行作业时,SCM 签出已成功执行。但是它会引发编译错误。
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 101: unexpected token: https://discord.com/api/webhooks/123456789012345678/me-3_LacrufNcvKg-U @ line 101, column 27.
webhookURL: "https://discord.com/api/webhooks/123456789012345678/me-3_LacrufNcvKg-U",
此脚本是使用 Jenkins 片段生成器生成的。生成器将 Webhook 作为最后一个参数。这样詹金斯会抛出以下编译错误
Missing required parameter: "webhookURL" @ line 100, column 13.
discordSend {
^
因此,我根据 Jenkins Discord Notifier 插件页面 https://plugins.jenkins.io/discord-notifier/ 上提供的示例进行了一些更改。我将单引号更改为双引号,将 webhook URL 移动为第一个参数等。我仍然收到编译错误。知道可能出了什么问题吗?
括号
()
和花括号 {}
在 Groovy 中不能自由互换:)。它是:
discordSend(
webhookURL: "https://discord.com/api/webhooks/123456789012345678/me-3_LacrufNcvKg-U",
discordSend description: 'Status of my Project',
footer: '',
image: '',
link: env.BUILD_URL,
result: currentBuild.currentResult,
scmWebUrl: '',
thumbnail: '',
title: JOB_NAME
)