简体   繁体   中英

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

[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.

Instead, try calling it like this: run_linux(tags) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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