如何在Jenkins Job DSL Groovy脚本中设置监视器视图的作业顺序?

时间:2019-05-31 08:40:09

标签: jenkins jenkins-groovy jenkins-job-dsl

我正在使用DSL脚本创建Build Monitor视图,但是API中没有设置作业顺序的方法。创建视图后,我可以在配置中手动设置顺序,但是我需要在脚本中进行设置。

我使用https://jenkinsci.github.io/job-dsl-plugin/#path/buildMonitorView作为参考。我怀疑唯一可能的方法是configure(Closure)方法,但是我仍然对如何执行有相同的疑问。

我当前的代码:

biuldMonitorView("name-of-the-view") {
    jobs {
        regex("some regex to include jobs")
        recurese()
    }
    // I would expect something like:
    view {
        orderByFullName()
    }
}

2 个答案:

答案 0 :(得分:0)

经过反复尝试和println的调用,我来到了这个解决方案:

biuldMonitorView("name-of-the-view") {
    jobs { // This part is as before
        regex("some regex to include jobs")
        recurse()
    }
    // The solution:
    view.remove(view / order)
    view / order(class: "com.smartcodeltd.jenkinsci.plugins.buildmonitor.order.ByFullName")
}

上述解决方案将作业顺序设置为“全名”,而不是默认的“名称”。

我在Configure SVN section of job-dsl-plugin找到了remove的主意,可以在jenkins-build-monitor-plugin的源代码中找到工作订单选项的完全限定名称。

答案 1 :(得分:0)

我今天有同样的问题,并设法通过以下方式获得了Aivaras的建议:

buildMonitorView("name-of-the-view") {
  // Set properties like jobs
  jobs { 
    regex("some regex to include jobs")
    recurse()
  }
  // Directly manipulate the config to set the ordering
  configure { view ->
    view.remove(view / order)
    view / order(class: "com.smartcodeltd.jenkinsci.plugins.buildmonitor.order.ByFullName")
  }