简体   繁体   English

Jenkins Pipeline Groovy传递数组来运行

[英]Jenkins Pipeline Groovy pass in array to function

I'm setting an array like this 我正在设置这样的数组

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

I'm trying to pass it into a function like 我试图把它传递给像这样的函数

 run_linux("${tags}")

My function looks like 我的功能看起来像

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

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

So what it looks like in jenkins is this 那么jenkins的样子就是这个

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

It seems to be treating what got passed in as a string not an array. 它似乎将传入的内容视为字符串而不是数组。

You are indeed passing a string into the run_linux function - specifically, the string "${tags}" , where tags is being coerced into a string via string interpolation. 您确实将字符串传递给run_linux函数 - 特别是字符串"${tags}" ,其中tags通过字符串插值强制转换为字符串。

Instead, try calling it like this: run_linux(tags) . 相反,尝试这样调用它: run_linux(tags)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM