Jenkins array variable in environment tag/body

我怕爱的太早我们不能终老 提交于 2019-12-13 03:47:39

问题


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 {
    }
}

回答1:


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()
    }
}


来源:https://stackoverflow.com/questions/53743885/jenkins-array-variable-in-environment-tag-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!