我正在使用Jenkins与Throttle并发构建插件,以确保测试作业中对USB设备的独占访问。我使用参数化的作业,并带有一个名为MODE的参数。对于某些模式值,测试使用USB设备,而对于其他模式值,测试不使用USB设备。我正在编写一个Groovy脚本来运行测试。是否可以在脚本中分配"Multi-Project Throttle Category“,以便我可以根据我的模式参数的值来分配它?谢谢
发布于 2017-04-04 16:47:10
就地修改类别对我不起作用。相反,我必须创建一个新的ThrottleJobProperty并添加它:
ThrottleJobProperty jobProperty = item.getProperty(ThrottleJobProperty)
println("ThrottleJobProperty of " + item.name + " has categories: " + jobProperty?.categories)
String category = "long-running"
if (!jobProperty?.categories?.contains(category)) {
if (jobProperty != null) item.removeProperty(jobProperty)
List<String> categories = jobProperty != null ?
new ArrayList<String>(jobProperty.categories) :
new ArrayList<String>()
categories.add(category)
jobProperty = new ThrottleJobProperty(
/*maxConcurrentPerNode:*/ 0,
/*maxConcurrentTotal:*/ 0,
/*categories:*/ categories,
/*throttleEnabled:*/ true,
/*throttleOption:*/ 'category',
/*limitOneJobWithMatchingParams:*/ false,
/*paramsToUseForLimit:*/ '',
/*matrixOptions:*/ null
)
item.addProperty(jobProperty)
println("Assigning ThrottleJobProperty.categories for " + item.name + ": " + jobProperty?.categories)
item.save()
}发布于 2014-03-07 21:15:09
我发现这是可行的
tjp = myjob.getProperty(hudson.plugins.throttleconcurrents.ThrottleJobProperty)
// see what we got
if(tjp != null) {
println("--- Throttle concurrents for " + myjob.name + " ---")
try {
println "Got this: " + tjp.categories + " items " + tjp.categories.size
} catch(Exception e) {
println(tjp.categories)
}
}
// change the first one
tjp.categories[0] = "myCategory"
// update job properties
myjob.addProperty(tjp)https://stackoverflow.com/questions/20733669
复制相似问题