2017-09-26 48 views
0

我設置這樣的詹金斯管道Groovy的傳遞陣列的功能

def tags = [ 
    "zookeeper", 
    "postgres", 
    "postgres-maps", 
    "kudu-master", 
    "redis-master", 
    "consul", 
    "dcos-bootstrap"] 

數組我試圖把它傳遞到一個函數像

run_linux("${tags}") 

我的功能看起來像

def run_linux(tags) { 
    def tasks = [:] 

    for (i = 0; i < tags.size(); i++) { 
    def tag = "${tags[i]}" 
    tasks["${tag}"] = { 
     stage ("${tag}"){ 
      sh .. 
     } 
    } 

所以它看起來像詹金斯是這樣的

[Pipeline] [[] stage 
[Pipeline] [[] { ([) 
[Pipeline] [z] stage 
[Pipeline] [z] { (z) 
[Pipeline] [o] stage 
[Pipeline] [o] { (o) 
[Pipeline] [k] stage 
[Pipeline] [k] { (k) 

它似乎是治療什麼傳遞作爲一個字符串,而不是一個數組。

回答

1

確實將一個字符串傳入run_linux函數 - 具體地說,是字符串"${tags}",其中tags被強制爲通過字符串插值的字符串。

請改爲嘗試像這樣調用它:run_linux(tags)