Jenkins数组变量在环境标记/正文中

问题描述 投票:0回答:1

我想在Jenkins管道的环境标签/主体中定义一个字符串数组。这似乎不起作用;詹金斯不承认阵列。

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

pipeline {
    agent {
        label 'Test'
    }

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

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

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

pipeline {
    agent {
        label 'Test'
    }

    environment {
    }
}
jenkins jenkins-pipeline
1个回答
0
投票

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

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

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

pipeline {
    agent {
        label 'Test'
    }

    environment {
      ARRAY=getArray()
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.