因此,我尝试在 Jenkinsfile 中使用 slackSend 在通道上发布构建状态,并且我尝试显式定义这样的所有内容 - (出于某种原因,我必须这样定义它)
WithCredentials([string(credentialsId: 'theSlackToken', variable: 'slackCredentials')]) {
slackSend (channel: '@johnsmith', message: 'hello there', color: '#3eb991', failOnError: true, teamDomain: 'myteamsubdomain', token: slackCredentials)
}
但是当我在 Jenkinsfile 中使用以上这些行时,我收到错误消息,提示没有这样的 DSL 方法字符串。
请帮助我,我将非常感谢任何建议。
这里有几个问题:
slackSend (channel: '@johnsmith', message: 'hello there', color: '#3eb991', tokenCredentialId: 'theSlackToken')
重要提示:凭据应该是密文!!!
无需在每个 slackSend 命令中都使用 tokenCredentialId,您可以将其设置为该 Jenkins 的通用 slack 令牌。通过 Jenkins -> 管理 Jenkins -> 配置系统,然后查找 Slack,并输入您要使用的令牌的正确凭据。然后你可以使用:
slackSend (channel: '@johnsmith', message: 'hello there', color: '#3eb991'
在 slack 命令中使用 tokenCredentialId 可以覆盖当前的全局令牌,这样您就可以在 Jenkins 内的 slack 应用程序之间切换。
欲了解更多信息: https://plugins.jenkins.io/slack/