繁体   English   中英

将 Groovy 中的所有 JSON 替换为 Jenkins

[英]Replaceall JSON in Groovy for Jenkins

希望你和你的家人都好,我需要问一些菜鸟。 我现在正在为 jenkins 中的一些项目使用 Groovy。 我的 json 文件有很多名称:“Ingress_1”、“Ingress_2”等等,所以我会尝试使用著名的 replaceAll 但没有任何反应:

这是代码:

import groovy.json.JsonSlurper
if(the_suite.equals("Asset_important"))
{
def process =["cat",".blabla/jsonfile.json"].execute()
def jsonSlurper = new JsonSlurper()
List<String> artifacts = new ArrayList<String>()
def object_a = jsonSlurper.parseText(process.text)
def object = object_a.replaceAll(/_/, ' ')

assert object instanceof Map
for(i=0;i<object.data.size();i++){        artifacts.add(object.data[i].feature)
 }

我已经尝试过replaceAll("/_/", ' ')

感谢您阅读本文:)

replaceAll()仅为String定义,但您试图在JsonSlurper.parseText()的结果上使用它,其类型为Object

这应该有效:

def object = jsonSlurper.parseText(process.text.replaceAll('_', ' '))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM