Search code examples
jenkinsgroovyenvironment-variablesjenkins-pipeline

Jenkinsfile use array in environment


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]"


Solution

  • I resolved this one. I used this def method

        def values = """
            val1
            val2
                     """
    

    My environment:

        environment {
         MY_VALUES = values.stripMargin()
    }