[英]Parse the Jenkins Pipeline in to JSON using Java (get all strings/text between two curly braces)
I have a requirement to parse the Jenkins pipeline script and convert into JSON using JAVA我需要解析 Jenkins 管道脚本并使用 JAVA 转换为 JSON
Input:输入:
pipeline{
agent any
stages{
stage('stage-1'){
steps{
script {
echo 'hello stage1 world'
}
}
}
stage('stage-2'){
steps{
script {
echo 'hello stage2 world'
}
}
}
}
}```
**Output required**
"pipeline": {
"stages": [
{
"id": "stage1,
"steps": [
{
"type": "script",
"value" :"hello stage1 world"
}
]
},
{
"id": "stage2,
"steps": [
{
"type": "script",
"value" :"hello stage2 world"
}
]
}
]
}
Methods/Approach which i am using: I thought will use regex function to get all content between two curly braces & parsing the same.我正在使用的方法/方法:我认为将使用正则表达式 function 来获取两个花括号之间的所有内容并解析相同的内容。 however i am new to regex, could you please guide me right approach
但是我是正则表达式的新手,请您指导我正确的方法
The JSON objects will have a "{" opening tag and a closing "}" tag. JSON 对象将有一个“{”开始标记和一个结束“}”标记。 To get this requirement it would be better to devise a custom parser as per your JSON structure.
要获得此要求,最好根据您的 JSON 结构为 devise 自定义解析器。
However, if you are in need of creating a JSON format jenkins job file then you can refer the python based module "jenkins job builder"但是,如果您需要创建 JSON 格式 jenkins 作业文件,那么您可以参考基于 python 的模块“jenkins job builder”
https://docs.openstack.org/infra/jenkins-job-builder/ https://docs.openstack.org/infra/jenkins-job-builder/
This module helps you define the jenkins jobs in JSON format.此模块帮助您以 JSON 格式定义 jenkins 作业。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.