Groovy OpenShift使用JSON值创建Configmap

Groovy OpenShift使用JSON值创建Configmap,groovy,openshift,Groovy,Openshift,我想创建一个配置映射,使用JSON对象作为它的值 JSON对象看起来像这样,(variable name=manifestJSON) 然后我想创建一个configmap,它接受这个JSON对象并将其添加为configmap的值 我想让它工作的命令是 def osCmd = "create configmap manifest-config" + " --from-literal=manifest.os_config_branch=${envVars.OS_CONFIG_BRANC

我想创建一个配置映射,使用JSON对象作为它的值

JSON对象看起来像这样,(
variable name=manifestJSON

然后我想创建一个configmap,它接受这个JSON对象并将其添加为configmap的值

我想让它工作的命令是

def osCmd = "create configmap manifest-config" +
        " --from-literal=manifest.os_config_branch=${envVars.OS_CONFIG_BRANCH}" +
        " --from-literal=manifest.os_server=${envVars.OPENSHIFT_SERVER_URL}" 
        " --from-literal=manifest.os_manifest=${manifestJSON}"
os.call(osCmd)
OpenShift客户端出现以下错误:

10:23:37错误:无法添加键manifest.os\u manifest,已存在另一个同名键:map[manifest.os\u config\u分支:部署编排器manifest.os\u服务器:,manifest.os\u manifest:AppreproversionMap:repoA:1.0.0.131]。

因此,groovy或OpenShift在JSON对象中看到JSON对象,无法处理它


我试图避免使用
--from file
,因为我必须写入磁盘,然后运行命令,我担心这会在Jenkins环境中导致问题,因为多个项目发生了多个部署。

解决方案非常简单,我在尝试时过度考虑角色转义各种解决方案

为了在创建configmap(或机密)时使用JSON作为值,需要在JSON对象本身周围添加
'

def osCmd = "create configmap manifest-config" +
        " --from-literal=manifest.os_config_branch=${envVars.OS_CONFIG_BRANCH}" +
        " --from-literal=manifest.os_server=${envVars.OPENSHIFT_SERVER_URL}" 
        " --from-literal=manifest.os_manifest='${manifestJSON}'" // <----- single quotes
os.call(osCmd)
def osCmd=“创建configmap清单配置”+
“--from literal=manifest.os_config_branch=${envVars.os_config_branch}”+
“--from literal=manifest.os_server=${envVars.OPENSHIFT_server_URL}”
“--from literal=manifest.os_manifest='${manifestJSON}'”//
def osCmd = "create configmap manifest-config" +
        " --from-literal=manifest.os_config_branch=${envVars.OS_CONFIG_BRANCH}" +
        " --from-literal=manifest.os_server=${envVars.OPENSHIFT_SERVER_URL}" 
        " --from-literal=manifest.os_manifest='${manifestJSON}'" // <----- single quotes
os.call(osCmd)