环境标签/正文中的Jenkins数组变量

时间:2018-12-12 13:15:26

标签: jenkins jenkins-pipeline

我想在Jenkins管道的环境标签/主体中定义一个字符串数组。这似乎行不通; jenkins无法识别数组。

环境变量值必须是单引号,双引号或函数调用。 @第x行,第y列。         myArray = [

pipeline {
    agent {
        label 'Test'
    }

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

下一个代码似乎可行,但是我希望环境标记中包含所有字段/设置。

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

pipeline {
    agent {
        label 'Test'
    }

    environment {
    }
}

1 个答案:

答案 0 :(得分:0)

  

环境变量值必须是单引号,双引号或函数调用。

您可以定义一个函数,该函数将返回您的数组。

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

pipeline {
    agent {
        label 'Test'
    }

    environment {
      ARRAY=getArray()
    }
}
相关问题