如何使用脚本添加多项目节流类别

时间:2016-01-18 15:28:14

标签: jenkins jenkins-plugins throttling jenkins-groovy

我正在使用Jenkins和Throttle Concurrent Builds插件并尝试在jenkins配置中添加Throttle Category(Jenkins => manage Jenkins => Configure System => Throttle Concurrent Builds)。是否可以使用groovy进行配置?感谢。

1 个答案:

答案 0 :(得分:2)

 String expectedLabel = "testLabel";
 Integer expectedMax = new Integer(1);

 ThrottleJobProperty.ThrottleCategory category =
 new ThrottleJobProperty.ThrottleCategory('testCategoryName3', 0, 0, null);
 List<ThrottleJobProperty.NodeLabeledPair> nodeLabeledPairs = category.getNodeLabeledPairs();
 nodeLabeledPairs.add(new ThrottleJobProperty.NodeLabeledPair(expectedLabel, expectedMax));

  ThrottleJobProperty.DescriptorImpl descriptor = Jenkins.getInstance().getDescriptorByType(ThrottleJobProperty.DescriptorImpl.class)

  categories = descriptor.getCategories()
  categories.add(category)
  descriptor.save()