Home > database >  Jenkinsfile use array in environment
Jenkinsfile use array in environment

Time:06-27

My code is using VALUES.each() method, it works fine when I have

environment{

    VALUES = "val1, val2"
}

But, I need to have a list from each line so that it can be read easily:

Something like:

environment {
VALUES =
 "val1",
 "val2"
}

I tried using [] and {} - didn't work, tried adding "\n" - no luck.

Tried using method def and then call it from environment:

def getArray(){
  return [
  'val1', 
  'val2'
  ]
}

but then it gives me "[val1" and "val2]"

CodePudding user response:

I resolved this one. I used this def method

    def values = """
        val1
        val2
                 """

My environment:

    environment {
     MY_VALUES = values.stripMargin()
}
  • Related