Jenkins DSL:Job SLack发布者:baseUrl()方法不可用

时间:2018-01-24 12:25:25

标签: jenkins dsl slack

我使用Jenkins 2.63和Slack Notifier插件2.2

我需要通过Job DSL使用SlackNotifier生成作业,但是我无法在DSL中设置基本URL,我收到此消息:

错误:(脚本,第145行)没有方法签名: baseUrl()适用于参数类型:(java.lang.String)值:[https://my.domain.slack.com/services/hooks/jenkins-ci/]可能的解决方案: authToken(),authTokenCredentialId(),botUser(),commitInfoChoice(),customMessage(),includeCustomMessage(),includeTestSummary(),notifyAborted(),notifyBackToNormal(),notifyFailure(),notifyNotBuilt(),notifyRegression(),notifyRepeatedFailure( ),notifySuccess(),notifyUnstable(),room(),sendAs(),startNotification(),teamDomain()完成:失败

这是我的DSL脚本

        publishers  {
          def slackParam = new groovy.json.JsonSlurper().parse(new File(channelFile))

          slackNotifier {
            baseUrl(slackParam.url)
            authTokenCredentialId(slackParam.authTokenCredentialId) 
            includeTestSummary(true) 
            notifyAborted(true) 
            notifyBackToNormal(true) 
            notifyFailure(true) 
            notifyNotBuilt(true) 
            notifyRegression(true) 
            notifyRepeatedFailure(true) 
            notifyUnstable(true)
            room(slackParam.room) 
          }
        }

但是在作业config.xml中我可以找到这个参数。

有人可以帮我设置基本网址参数吗?

非常感谢。

1 个答案:

答案 0 :(得分:3)

使用配置阻止:https://github.com/jenkinsci/job-dsl-plugin/wiki/The-Configure-Block

  configure { project ->
    project / publishers << 'jenkins.plugins.slack.SlackNotifier' {
      baseUrl("https://whatever.slack.com/services/hooks/jenkins-ci/")
      room("#room")
      notifyAborted(true)
      notifyFailure(true)
      notifyNotBuilt(false)
      notifyUnstable(true)
      notifyBackToNormal(true)
      notifySuccess(true)
      notifyRepeatedFailure(false)
      startNotification(false)
      includeTestSummary(false)
      includeCustomMessage(true)
      customMessage("Environment")
      sendAs(null)
      commitInfoChoice("AUTHORS_AND_TITLES")
      teamDomain("yourDomain")
      authTokenCredentialId("token")
    }
  }

将这个步骤放在工作的底部。您应该看到作业的UI和config.xml中反映的更改。