实现Jenkinsfile与Json的转换
最近在作个需求,须要支持Jenkinsfile和json的转换。html
方法1:使用现有的jenkins插件
参考的是这篇文章。下面介绍一下将插件打包成镜像的步骤:git
本地安装jdk和maven,jdk建议采用的版本为8(该工程会依赖一个名为tools.jar的包,jdk 9以后移除了该包)github
若是本地没有找到tools.jar,能够下载一个1.8版本的jdk,而后在pom.xml中增长以下依赖docker
jdk.tools
jdk.tools
1.8.0
system
/root/jdk1.8.0_271/lib/tools.jar
在/root/.m2/目录下建立settings.xml,内容来自Jenkins官方:maven
org.jenkins-ci.tools
jenkins
true
repo.jenkins-ci.org
https://repo.jenkins-ci.org/public/
repo.jenkins-ci.org
https://repo.jenkins-ci.org/public/
repo.jenkins-ci.org
https://repo.jenkins-ci.org/public/
m.g.o-public
执行 mvn install进行编译编辑器
因为主要用到的是Jenkinsfile和json之间的转换关系,所以主要用的是以下两个REST API:ui
Conversion to JSON representation from Jenkinsfilethis
URL: JENKINS_URL/pipeline-model-converter/toJson
Parameters: jenkinsfile - the Jenkinsfile contents
Info: Takes a Jenkinsfile and converts it to the JSON representation for its pipeline step.
Returns: JSON with a result field that will either be success or failure. If success, the JSON representation will be in the json field. If failure, there'll be an additional array in the errors field of the error messages encountered.
Conversion to Jenkinsfile from JSON representationatom
URL: JENKINS_URL/pipeline-model-converter/toJenkinsfile
P