Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins array variable in environment tag/body

I would like to define an array of strings within the environment tag/body of the Jenkins pipeline. This doesn't seem to work; jenkins doesn't recognize the array.

Environment variable values must either be single quoted, double quoted, or function calls. @ line x, column y. myArray= [

pipeline {
    agent {
        label 'Test'
    }

    environment {
        myArray = [
            "Item1",
            "Item2",
            "Item3"
        ]
    }
}

The next code seems to work, but I would like to have all fields/ settings in the environment tag.

def myArray = [
            "Item1",
            "Item2",
            "Item3"
        ]

pipeline {
    agent {
        label 'Test'
    }

    environment {
    }
}
like image 940
Odrai Avatar asked Oct 20 '25 04:10

Odrai


1 Answers

Environment variable values must either be single quoted, double quoted, or function calls.

You can define a function which will return your array.

def getArray(){
  return ['Item1', 'Item2', 'Item3']
}

pipeline {
    agent {
        label 'Test'
    }

    environment {
      ARRAY=getArray()
    }
}
like image 140
edbighead Avatar answered Oct 22 '25 05:10

edbighead