如何使用脚本添加多项目限制类别

How to add Multi-Project Throttle Category using script

我将 Jenkins 与 Throttle Concurrent Builds 插件一起使用,并尝试在 Jenkins 配置中添加 Throttle 类别(Jenkins=>管理 Jenkins=>配置系统=>Throttle 并发构建)。是否可以使用 groovy 配置它?谢谢。

 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()