[转] 在Jenkins Pipeline DSL中 遍历 groovy list
[From] https://stackoverflow.com/questions/36360097/iterating-a-groovy-list-in-jenkins-pipeline-dsl
// 定义一个List,并向里面加入一些元素
def componentList = [] def componentMapEntry1 = [:] componentMapEntry1['componentName']="Dashboard_Core" componentList << componentMapEntry1 def componentMapEntry2 = [:] componentMapEntry2['componentName']="Dashboard_Equities" componentList << componentMapEntry2 def cme3 = [:] cme3["componentName"] = "home" componentList << cme3
echo "size of list "+componentList.size()
// pipeline里打印size() [Pipeline] echo size of list 3
println componentList
// pipeline里直接打印list [Pipeline] echo [{componentName=Dashboard_Core}, {componentName=Dashboard_Equities}, {componentName=home}]
for (i = 0; i <componentList.size(); i++) { println componentList[i] } // pipeline里遍历list [Pipeline] echo {componentName=Dashboard_Core} [Pipeline] echo {componentName=Dashboard_Equities} [Pipeline] echo {componentName=home}