我试图用 jenkins 管道显示 json 文件,但我没有显示正确的文件格式 每次build的时候都发现文件格式变了
文件 suivi.installation.json
{
"receptions": [{
"loginacteur": "zex9450",
"codeapplication": "SDD",
"version": "1.0",
"datereception": "2019-08-01",
"numtran": 15000,
"lien": "",
"datepriseencompte": "2019-08-01",
"composants": [{
"composant": "Gestion sapp ear",
"version": "1.0.8",
"technologie": "JBOSS",
"installations": [{
"environnement": "SDD QF",
"modedeploiement": "AUTO (JENKINS)",
"dateinstallation": "2019-07-31",
"loginacteur": "zex9450"
}]
}
]
}]
}
文件 Jenkins 文件
stage('Publication dans Suivi Installation CNI') {
agent {label 'Jenkins-Pega-Master'}
steps {
script {
def json = readJSON file: './output/suivi_installation.json'
echo "${json}"
}
}
}
控制台输出
[Pipeline] withEnv
[Pipeline] {
[Pipeline] script
[Pipeline] {
[Pipeline] readJSON
[Pipeline] echo
[receptions:[[loginacteur:zex9450, codeapplication:SDD, version:1.0, datereception:2019-08-01, numtran:15000, lien:, datepriseencompte:2019-08-01, composants:[[composant:Gestion sapp ear, version:1.0.8, technologie:JBOSS, installations:[[environnement:SDD QF, modedeploiement:AUTO (JENKINS), dateinstallation:2019-07-31, loginacteur:zex9450]]]]]]]
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
最佳答案
您可以使用 JsonOutput 类进行 pretty-print ,但您首先需要转换格式才能这样做(这已经提到)。替代方案:
import groovy.json.JsonOutput
....
steps {
script {
def json = readJSON file: './output/suivi_installation.json'
def jsonFormat = JsonOutput.toJson(json)
prettyJSON = JsonOutput.prettyPrint(jsonFormat)
echo "${prettyJSON}"
}
}
控制台输出:
{
"receptions": [
{
"loginacteur": "zex9450",
"codeapplication": "SDD",
"version": "1.0",
"datereception": "2019-08-01",
"numtran": 15000,
"lien": "",
"datepriseencompte": "2019-08-01",
"composants": [
{
"composant": "Gestion sapp ear",
"version": "1.0.8",
"technologie": "JBOSS",
"installations": [
{
"environnement": "SDD QF",
"modedeploiement": "AUTO (JENKINS)",
"dateinstallation": "2019-07-31",
"loginacteur": "zex9450"
}
]
}
]
}
]
}
关于json - 使用 jenkins 管道显示 Json 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57327648/