Jenkins pipeline Jenkinsfile and Json conversion

Some time ago, I investigated the kubesphere of Qingyun, and accidentally found a plugin, pipeline-model-definition-plugin , which used to convert the pipeline and json of Jenkins. I might have paid attention to this plugin before, but I did n’t pay much attention to it. I didn't find the plugin above, I don't know why, so let me explain it briefly.

1. Installation

The plugin for jenkins is not provided above, so it can only be packaged and compiled by itself. The packaging process is also given on github: cd pipeline-model-definition && mvn install && mvn hpi: run, and then upload the hpi file to the plugin.

Second, the main api interface

2.1 Obtain pipeline JSON format JSON Schema

URL: JENKINS_URL / pipeline-model-schema / json Info: Get jenkinsfile Returns: json in json format

2.2 Convert jenkinsfile to json format

URL: JENKINS_URL / pipeline-model-converter / toJson Parameters: text in jenkinsfile format Info: Obtain the jenkinsfile, and then convert it to json. Returns: If successful, returns json, otherwise returns an error message

2.3 Convert json format to jenkinsfile

URL: JENKINS_URL / pipeline-model-converter / toJenkinsfile Parameters: json format file Info: Get the json format file, and then convert it to jenkinsfile Returns: If successful, return the converted jenkinsfile, if it fails, return an error message.

There are some other interfaces (such as: verify json, groovy syntax conversion, etc.) that will not be explained.

Three, Demo

Here, the simplest example given on the official website is converted into json, and the whole process of construction-> unit testing-> deployment

pipeline {
    agent any
    stages {
        stage(''Build'') { steps { echo ''Building..'' } } stage(''Test'') { steps { echo ''Testing..'' } } stage(''Deploy'') { steps { echo ''Deploying....'' } } } }

Submit a request in postman:

You can get the results returned:

{
    "status": "ok",
    "data": { "result": "success", "json": { "pipeline": { "stages": [ { "name": "Build", "branches": [ { "name": "default", "steps": [ { "name": "echo", "arguments": [ { "key": "message", "value": { "isLiteral": true, "value": "Building.." } } ] } ] } ] }, { "name": "Test", "branches": [ { "name": "default", "steps": [ { "name": "echo", "arguments": [ { "key": "message", "value": { "isLiteral": true, "value": "Testing.." } } ] } ] } ] }, { "name": "Deploy", "branches": [ { "name": "default", "steps": [ { "name": "echo", "arguments": [ { "key": "message", "value": { "isLiteral": true, "value": "Deploying...." } } ] } ] } ] } ], "agent": { "type": "any" } } } } }

4. Summary

I have previously published an article explaining how to use Jenkins x to make something similar to Alibaba Cloud, but I have not found this plug-in before, which leads to the conversion of the syntax. It is necessary to cut the pipeline syntax by myself. The wheels need to be rebuilt again. In general, if the planning and design are good, it should be comparable to the Yunxiao product on the surface.

Guess you like

Origin www.cnblogs.com/lvcisco/p/12689927.html