2013-12-22 34 views
1

我正在使用Jenkins和油門併發構建插件來確保在測試作業中獨佔訪問USB設備。我使用參數化作業,並使用名爲MODE的參數。對於某些MODE值,測試使用USB設備,對於其他MODE值,測試不使用USB設備。 我正在編寫用於運行測試的Groovy腳本。 是否可以在腳本中分配「Multi-Project Throttle Category」,以便我可以根據我的MODE參數的值分配它? 感謝如何在腳本中分配「多項目油門分類」

回答

0

我發現這個工作

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) 
+0

這是否修改作業配置或構建屬性?它在Throttle Concurrent Builds插件阻止其執行之前是否生效?還是它從外部修改作業,然後觸發構建它?我想要一個參數化的作業,其中參數基本上是多項目節流類別,我可以使用相同和不同的參數運行多個作業,以及具有不同參數的相同作業,並且每個類別都可以適當地阻止(類似於您的使用案例:通過USB連接的不同設備) – Joe

0

修改就地類別對我沒有工作。相反,我必須創建一個新的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() 
}