在Jenkins作业DSL定义中使用slackNotifier时gradle测试失败

在Jenkins作业DSL定义中使用slackNotifier时gradle测试失败,jenkins,jenkins-job-dsl,Jenkins,Jenkins Job Dsl,更新: 从自动生成的DSL wiki条目的底部。。。生成的DSL仅在Jenkins中运行时受支持,… 由于slackNotifier是由DSL生成的,所以似乎没有办法在我们特定的基础设施中测试这一点。我们将编写一个函数,使用configure块生成配置 我有一个失败的gradle测试,尽管它在Jenkins中使用时似乎运行良好 摘录 //package master // GitURL def gitUrl = 'https://github.com/team/myapp' def slack

更新: 从自动生成的DSL wiki条目的底部
。。。生成的DSL仅在Jenkins中运行时受支持,…

由于slackNotifier是由DSL生成的,所以似乎没有办法在我们特定的基础设施中测试这一点。我们将编写一个函数,使用configure块生成配置


我有一个失败的gradle测试,尽管它在Jenkins中使用时似乎运行良好

摘录

//package master
// GitURL
def gitUrl = 'https://github.com/team/myapp'
def slackRoom = null

job('seed-dsl') {
    description('This seed is updated from the seed-dsl-updater job')
    properties {
        //Set github project URL
        githubProjectUrl(gitUrl)
    }
    ...
    // publishers is another name for post build steps
    publishers {
        mailer('', false, true)
        slackNotifier {
            room(slackRoom)
            notifyAborted(true)
            notifyFailure(true)
            notifyNotBuilt(true)
            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)
        }
    }
}
当我用slackNotifier声明注释掉时,
gradle test
命令工作正常,但在启用时失败,出现以下错误:

摘录

据《金融时报》报道,slackNotifer自1.47以来一直受到支持。在我的示例中,我使用1.48。我在插件版本1.50中看到了相同的错误

摘录

根据[testing docs]*()的建议,还包括以下内容


我需要做什么才能成功地测试我的工作定义。这是一个bug,还是我错过了其他东西?

删除了不正确的回复


编辑

我看我没抓住要点

新的方法是重用插件公开的@DataBoundConstructor,因此假设新插件具有DataBoundConstructor,则无需编写任何东西来支持它

您有这样一个问题-注意DSL为您转换小写的第一个字母

@DataBoundConstructor
public SlackNotifier(
    final String teamDomain, 
    final String authToken, 
    final String room, 
    final String buildServerUrl,
    final String sendAs, 
    final boolean startNotification, 
    final boolean notifyAborted, 
    final boolean notifyFailure,
    final boolean notifyNotBuilt, 
    final boolean notifySuccess, 
    final boolean notifyUnstable, 
    final boolean notifyBackToNormal,
    final boolean notifyRepeatedFailure, 
    final boolean includeTestSummary, 
    CommitInfoChoice commitInfoChoice,
    boolean includeCustomMessage, 
    String customMessage) {
    ...
}
不幸的是,参数列表中有一个嵌入类型,它没有DataBoundConstructor,也没有枚举

public enum CommitInfoChoice {
    NONE("nothing about commits",                             false, false),
    AUTHORS("commit list with authors only",                  true,  false),
    AUTHORS_AND_TITLES("commit list with authors and titles", true,  true);
    ...
}
我要说的是,除非嵌套枚举实现了一个数据绑定构造函数,并且还有一个描述符,否则它将无法解决这个问题,对不起

我没有这个插件,但是你可以通过这个插件查看一个真正创建的工作的XML,看看这一部分的内容。我怀疑这是一个嵌套结构


您可以尝试链接到关于通用方法的帖子

我们也遇到了这个问题。我们的解决方案是将我们在jenkins上使用的slack插件版本添加到gradle的插件列表中

更具体地说,在依赖项下的
build.gradle
文件中,我们添加了以下代码以包含插件,从而允许自动生成的DSL工作

您可以看到这里描述的内容以及
testPlugins
旁边的另一个插件示例:

例如:

dependencies {
  ...
  // plugins to install in test instance
  testPlugins 'org.jenkins-ci.plugins:ghprb:1.31.4'
  testPlugins 'com.coravy.hudson.plugins.github:github:1.19.0'
}

正如我在问题中所说的,注意到由于1.47 SlackNotifier被弃用以支持SlackNotifier,所以不,我不想使用弃用的DSL。我更改了我的答案,希望更好,但可能不是好消息。我得出了相同的结论,但您提供了一些相关细节。谢谢。枚举不需要
@DataBoundConstructor
,您可以将枚举值直接用作字符串,例如
CommitInfoChoice
枚举的
'NONE'
'AUTHORS\u AND\u TITLES'
@DataBoundConstructor
public SlackNotifier(
    final String teamDomain, 
    final String authToken, 
    final String room, 
    final String buildServerUrl,
    final String sendAs, 
    final boolean startNotification, 
    final boolean notifyAborted, 
    final boolean notifyFailure,
    final boolean notifyNotBuilt, 
    final boolean notifySuccess, 
    final boolean notifyUnstable, 
    final boolean notifyBackToNormal,
    final boolean notifyRepeatedFailure, 
    final boolean includeTestSummary, 
    CommitInfoChoice commitInfoChoice,
    boolean includeCustomMessage, 
    String customMessage) {
    ...
}
public enum CommitInfoChoice {
    NONE("nothing about commits",                             false, false),
    AUTHORS("commit list with authors only",                  true,  false),
    AUTHORS_AND_TITLES("commit list with authors and titles", true,  true);
    ...
}
dependencies {
  ...
  // plugins to install in test instance
  testPlugins 'org.jenkins-ci.plugins:ghprb:1.31.4'
  testPlugins 'com.coravy.hudson.plugins.github:github:1.19.0'
}