У меня есть несколько JSON файлов со следующими структурами
FILE1. json
{
"Plugins": [
{
"Name": "Async Http Client",
"Installation": [
{
"Version": "1.7.24.2",
"Enabled": true,
"URL": "http://wiki.jenkins-ci.org/display/JENKINS/Async+Http+Client+Plugin",
"Server": "Server1"
}
]
},
{
"Name": "Common API for Blue Ocean",
"Installation": [
{
"Version": "1.10.2",
"Enabled": true,
"URL": "https://wiki.jenkins-ci.org/display/JENKINS/Blue+Ocean+Plugin",
"Server": "Server1"
}
]
},
.
.
.
]
}
FILE2. json
{
"Plugins": [
{
"Name": "Async Http Client",
"Installation": [
{
"Version": "1.7.24.1",
"Enabled": true,
"URL": "http://wiki.jenkins-ci.org/display/JENKINS/Async+Http+Client+Plugin",
"Server": "Server2"
}
]
},
{
"Name": "Common API for Blue Ocean",
"Installation": [
{
"Version": "1.10.2",
"Enabled": true,
"URL": "https://wiki.jenkins-ci.org/display/JENKINS/Blue+Ocean+Plugin",
"Server": "Server2"
}
]
},
.
.
.
]
}
FILE3. json
{
"Plugins": [
{
"Name": "Common API for Blue Ocean",
"Installation": [
{
"Version": "1.10.1",
"Enabled": true,
"URL": "https://wiki.jenkins-ci.org/display/JENKINS/Blue+Ocean+Plugin",
"Server": "Server3"
}
]
},
{
"Name": "Support Core Plugin",
"Installation": [
{
"Version": "2.54",
"Enabled": true,
"URL": "https://wiki.jenkins.io/display/JENKINS/Support+Core+Plugin",
"Server": "Server3"
}
]
},
.
.
.
]
}
Я хочу объединить их в отдельный файл со следующей структурой, используя groovy
MergedFile. json
{
"Plugins": [
{
"Name": "Async Http Client",
"Installation": [
{
"Version": "1.7.24.2",
"Enabled": true,
"URL": "http://wiki.jenkins-ci.org/display/JENKINS/Async+Http+Client+Plugin",
"Server": "Server1"
},
{
"Version": "1.7.24.1",
"Enabled": true,
"URL": "http://wiki.jenkins-ci.org/display/JENKINS/Async+Http+Client+Plugin",
"Server": "Server2"
}
]
},
{
"Name": "Common API for Blue Ocean",
"Installation": [
{
"Version": "1.10.2",
"Enabled": true,
"URL": "https://wiki.jenkins-ci.org/display/JENKINS/Blue+Ocean+Plugin",
"Server": "Server1"
},
{
"Version": "1.10.2",
"Enabled": true,
"URL": "https://wiki.jenkins-ci.org/display/JENKINS/Blue+Ocean+Plugin",
"Server": "Server2"
},
{
"Version": "1.10.1",
"Enabled": true,
"URL": "https://wiki.jenkins-ci.org/display/JENKINS/Blue+Ocean+Plugin",
"Server": "Server3"
}
]
},
{
"Name": "Support Core Plugin",
"Installation": [
{
"Version": "2.54",
"Enabled": true,
"URL": "https://wiki.jenkins.io/display/JENKINS/Support+Core+Plugin",
"Server": "Server3"
}
]
},
.
.
.
]
}
Я ищу сценарий конвейера jenkins, использующий jenkins groovy. Файловая структура 3 файлов одинакова. Только содержимое файла может отличаться. Если есть какое-либо общее «Имя», «Установка» объединяется с тем же «Именем», как упомянуто выше.
Любая помощь приветствуется!
Редактировать: я пробовал что-то подобное ..
files = findFiles(glob: "*.json")
def input
def mergedjson = readJSON file:"${files[0]}"
for (f=1;f<files.size();f++)
{
input=readJSON file:"${files[f]}"
i = input.Plugins.size()
j = mergedjson.Plugins.size()
for (x=0;x<i;x++)
{
def json_status=0
for (y=0;y<j;y++)
{
if (input.Plugins[x].Name == mergedjson.Plugins[y].Name)
{
mergedjson.Plugins[y].Installation += input.Plugins[x].Installation
json_status=1
break;
}
}
if (json_status == 0)
mergedjson.Plugins[j++] = input.Plugins[x]
}
}
inventory=JsonOutput.prettyPrint(JsonOutput.toJson(mergedjson))
writeFile([file: "Inventory.json", text: inventory])
Я получаю следующую ошибку java .lang.StackOverflowError в java .lang.reflect.InvocationTargetException. (InvocationTargetException. java: 72) в sun.reflect.GeneratedMethodAccessor544 .invoke (Неизвестный источник) в sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl. java: 43) в java .lang.reflect.Method.invoke (Метод. java: 498) в org.codehaus. groovy .reflection.CachedMethod.invoke (CachedMethod. java: 93) в groovy .lang.MetaBeanProperty.getProperty (MetaBeanProperty. java: 59) в groovy .lang.PropertyValue.getValue. 1047 *: 42) в org.codehaus. groovy .runtime.DefaultGroovyMethods.getProperties (DefaultGroovyMethods. java: 389) в groovy. json .JsonOutput.getObjectProperties (JsonOutput. java: 327) groovy. json .JsonOutput.writeObject (JsonOut положить. java: 320) в groovy. json .JsonOutput.writeMap (JsonOutput. java: 458) в groovy. json .JsonOutput.writeObject (JsonOutput. java: 321) в groovy. json .JsonOutput.writeMap (JsonOutput. java: 458) в groovy. json .JsonOutput.writeObject (JsonOutput. java: 321) в groovy. json .JsonOutput.writeMap (JsonOutput. java: 458) в groovy. json .JsonOutput.writeObject (JsonOutput. java: 321). , .