环境标签/主体中的Jenkins数组变量 [英] Jenkins array variable in environment tag/body

查看:1033
本文介绍了环境标签/主体中的Jenkins数组变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

推荐答案

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

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

这篇关于环境标签/主体中的Jenkins数组变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆