update jenkins api

Signed-off-by: soulseen <sunzhu@yunify.com>
This commit is contained in:
Zhuxiaoyang
2019-04-30 18:56:46 +08:00
committed by zryfish
parent b416aa27bb
commit daab932e9f
5 changed files with 799 additions and 149 deletions

View File

@@ -259,7 +259,7 @@ func addWebService(c *restful.Container) error {
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs").
To(devopsapi.SearchPipelineRuns).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Search DevOps Pipelines runs.").
Doc("Search DevOps Pipelines runs in branch.").
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.QueryParameter("start", "start page").
@@ -271,14 +271,14 @@ func addWebService(c *restful.Container) error {
Param(webservice.QueryParameter("branch", "branch ").
Required(false).
DataFormat("branch=%s")).
Returns(http.StatusOK, RespOK, []devops.PipelineRun{}).
Writes([]devops.PipelineRun{}))
Returns(http.StatusOK, RespOK, []devops.PipeBranchRun{}).
Writes([]devops.PipeBranchRun{}))
// match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/"
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}").
To(devopsapi.GetPipelineRun).
To(devopsapi.GetPipeBranchRun).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get DevOps Pipelines run.").
Doc("Get DevOps Pipelines run in branch.").
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")).
@@ -286,12 +286,12 @@ func addWebService(c *restful.Container) error {
Param(webservice.QueryParameter("start", "start").
Required(false).
DataFormat("start=%d")).
Returns(http.StatusOK, RespOK, devops.PipelineRun{}).
Writes(devops.PipelineRun{}))
Returns(http.StatusOK, RespOK, devops.PipeBranchRun{}).
Writes(devops.PipeBranchRun{}))
// match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes"
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes").
To(devopsapi.GetPipelineRunNodes).
To(devopsapi.GetBranchPipeRunNodes).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get node on DevOps Pipelines run.").
Param(webservice.PathParameter("projectName", "devops project name")).
@@ -302,8 +302,8 @@ func addWebService(c *restful.Container) error {
Required(false).
DataFormat("limit=%d").
DefaultValue("limit=10000")).
Returns(http.StatusOK, RespOK, []devops.Nodes{}).
Writes([]devops.Nodes{}))
Returns(http.StatusOK, RespOK, []devops.BranchPipeRunNodes{}).
Writes([]devops.BranchPipeRunNodes{}))
// match "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log/?start=0"
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log").
@@ -382,7 +382,7 @@ func addWebService(c *restful.Container) error {
Returns(http.StatusOK, RespOK, devops.StopPipe{}).
Writes(devops.StopPipe{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/replay/
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/Replay/
webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/replay").
To(devopsapi.ReplayPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags).
@@ -482,7 +482,7 @@ func addWebService(c *restful.Container) error {
DataFormat("delay=%d")))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{}/runs/
webservice.Route(webservice.POST("/devops/{projectName}/pipeline/{pipelineName}/branches/{brancheName}/run").
webservice.Route(webservice.POST("/devops/{projectName}/pipeline/{pipelineName}/branches/{branchName}/run").
To(devopsapi.RunPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get pipeline artifacts.").
@@ -517,6 +517,104 @@ func addWebService(c *restful.Container) error {
Returns(http.StatusOK, RespOK, devops.Crumb{}).
Writes(devops.Crumb{}))
// match /job/init-job/descriptorByName/org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition/checkScriptCompile
webservice.Route(webservice.POST("/devops/check/scriptcompile").
To(devopsapi.CheckScriptCompile).
Metadata(restfulspec.KeyOpenAPITags, tags).
Consumes("application/x-www-form-urlencoded", "charset=utf-8").
Produces("application/json", "charset=utf-8").
Doc("Check pipeline script compile.").
Reads("value=\"\"").
Returns(http.StatusOK, RespOK, devops.CheckScript{}).
Writes(devops.CheckScript{}))
// match /job/init-job/descriptorByName/hudson.triggers.TimerTrigger/checkSpec
webservice.Route(webservice.GET("/devops/check/cron").
To(devopsapi.CheckCron).
Metadata(restfulspec.KeyOpenAPITags, tags).
Produces("application/json", "charset=utf-8").
Doc("Check pipeline script compile.").
Param(webservice.QueryParameter("value", "cpec value").
Required(true).
DataFormat("value=%s")).
Returns(http.StatusOK, RespOK, []devops.QueuedBlueRun{}).
Returns(http.StatusOK, RespOK, devops.CheckCronRes{}).
Writes(devops.CheckCronRes{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}").
To(devopsapi.GetPipelineRun).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get run pipeline in project.").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("runId", "pipeline run id")).
Returns(http.StatusOK, RespOK, devops.PipelineRun{}).
Writes(devops.PipelineRun{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}").
To(devopsapi.GetBranchPipe).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get Pipeline run in branch.").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")).
Returns(http.StatusOK, RespOK, devops.BranchPipe{}).
Writes(devops.BranchPipe{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/?limit=10000
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes").
To(devopsapi.GetPipeRunNodes).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get Pipeline run nodes.").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("runId", "pipeline run id")).
Param(webservice.QueryParameter("limit", "limit count").
Required(false).
DataFormat("limit=%d")).
Returns(http.StatusOK, RespOK, []devops.PipeRunNodes{}).
Writes([]devops.PipeRunNodes{}))
// match /blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?limit=
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps").
To(devopsapi.GetNodeSteps).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get steps in node.").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")).
Param(webservice.PathParameter("runId", "pipeline run id")).
Param(webservice.PathParameter("nodeId", "pipeline node id")).
Param(webservice.QueryParameter("limit", "limit count").
Required(false).
DataFormat("limit=%d")).
Returns(http.StatusOK, RespOK,[]devops.NodeSteps{}).
Writes([]devops.NodeSteps{}))
// match /pipeline-model-converter/toJenkinsfile
webservice.Route(webservice.POST("/devops/tojenkinsfile").
To(devopsapi.ToJenkinsfile).
Metadata(restfulspec.KeyOpenAPITags, tags).
Consumes("application/x-www-form-urlencoded").
Produces("application/json", "charset=utf-8").
Doc("Json to Jenkinsfile.").
Reads(devops.ReqJson{}).
Returns(http.StatusOK, RespOK,devops.NodeSteps{}).
Writes(devops.ResJenkinsfile{}))
// match /pipeline-model-converter/toJson
webservice.Route(webservice.POST("/devops/tojson").
To(devopsapi.ToJson).
Metadata(restfulspec.KeyOpenAPITags, tags).
Consumes("application/x-www-form-urlencoded").
Produces("application/json", "charset=utf-8").
Doc("Jenkinsfile to Json.").
Reads(devops.ReqJenkinsfile{}).
Returns(http.StatusOK, RespOK,devops.ResJson{}).
Writes(devops.ResJson{}))
c.Add(webservice)
return nil

View File

@@ -18,6 +18,7 @@
package devops
import (
"encoding/json"
"github.com/emicklei/go-restful"
log "github.com/golang/glog"
"kubesphere.io/kubesphere/pkg/models/devops"
@@ -34,7 +35,8 @@ func GetPipeline(req *restful.Request, resp *restful.Response) {
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func SearchPipelines(req *restful.Request, resp *restful.Response) {
@@ -44,7 +46,8 @@ func SearchPipelines(req *restful.Request, resp *restful.Response) {
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func SearchPipelineRuns(req *restful.Request, resp *restful.Response) {
@@ -57,37 +60,40 @@ func SearchPipelineRuns(req *restful.Request, resp *restful.Response) {
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func GetPipelineRun(req *restful.Request, resp *restful.Response) {
func GetPipeBranchRun(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId")
res, err := devops.GetPipelineRun(projectName, pipelineName, branchName, runId, req.Request)
res, err := devops.GetPipeBranchRun(projectName, pipelineName, branchName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func GetPipelineRunNodes(req *restful.Request, resp *restful.Response) {
func GetBranchPipeRunNodes(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId")
res, err := devops.GetPipelineRunNodes(projectName, pipelineName, branchName, runId, req.Request)
res, err := devops.GetBranchPipeRunNodes(projectName, pipelineName, branchName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func GetStepLog(req *restful.Request, resp *restful.Response) {
@@ -103,7 +109,7 @@ func GetStepLog(req *restful.Request, resp *restful.Response) {
parseErr(err, resp)
return
}
_, _ = resp.Write(res)
resp.Write(res)
}
func Validate(req *restful.Request, resp *restful.Response) {
@@ -115,7 +121,8 @@ func Validate(req *restful.Request, resp *restful.Response) {
return
}
_, _ = resp.Write(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func GetSCMOrg(req *restful.Request, resp *restful.Response) {
@@ -127,7 +134,8 @@ func GetSCMOrg(req *restful.Request, resp *restful.Response) {
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func GetOrgRepo(req *restful.Request, resp *restful.Response) {
@@ -140,7 +148,8 @@ func GetOrgRepo(req *restful.Request, resp *restful.Response) {
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func StopPipeline(req *restful.Request, resp *restful.Response) {
@@ -155,7 +164,8 @@ func StopPipeline(req *restful.Request, resp *restful.Response) {
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func ReplayPipeline(req *restful.Request, resp *restful.Response) {
@@ -170,7 +180,8 @@ func ReplayPipeline(req *restful.Request, resp *restful.Response) {
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func GetRunLog(req *restful.Request, resp *restful.Response) {
@@ -185,7 +196,7 @@ func GetRunLog(req *restful.Request, resp *restful.Response) {
return
}
_, _ = resp.Write(res)
resp.Write(res)
}
func GetArtifacts(req *restful.Request, resp *restful.Response) {
@@ -199,8 +210,8 @@ func GetArtifacts(req *restful.Request, resp *restful.Response) {
parseErr(err, resp)
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func GetPipeBranch(req *restful.Request, resp *restful.Response) {
@@ -212,8 +223,8 @@ func GetPipeBranch(req *restful.Request, resp *restful.Response) {
parseErr(err, resp)
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func CheckPipeline(req *restful.Request, resp *restful.Response) {
@@ -230,7 +241,7 @@ func CheckPipeline(req *restful.Request, resp *restful.Response) {
return
}
_, _ = resp.Write(res)
resp.Write(res)
}
func GetConsoleLog(req *restful.Request, resp *restful.Response) {
@@ -243,7 +254,7 @@ func GetConsoleLog(req *restful.Request, resp *restful.Response) {
return
}
_, _ = resp.Write(res)
resp.Write(res)
}
func ScanBranch(req *restful.Request, resp *restful.Response) {
@@ -256,7 +267,7 @@ func ScanBranch(req *restful.Request, resp *restful.Response) {
return
}
_, _ = resp.Write(res)
resp.Write(res)
}
func RunPipeline(req *restful.Request, resp *restful.Response) {
@@ -270,7 +281,8 @@ func RunPipeline(req *restful.Request, resp *restful.Response) {
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func GetStepsStatus(req *restful.Request, resp *restful.Response) {
@@ -286,26 +298,144 @@ func GetStepsStatus(req *restful.Request, resp *restful.Response) {
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func GetCrumb(req *restful.Request, resp *restful.Response) {
res, err := devops.GetCrumb(req.Request)
if err != nil {
parseErr(err, resp)
return
}
_ = resp.WriteAsJson(res)
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func CheckScriptCompile(req *restful.Request, resp *restful.Response) {
resBody, err := devops.CheckScriptCompile(req.Request)
if err != nil {
parseErr(err, resp)
return
}
// Jenkins will return different struct according to different results.
var resJson = new(devops.CheckScript)
if ok := json.Unmarshal(resBody, &resJson); ok != nil {
var resJson []interface{}
err := json.Unmarshal(resBody, &resJson)
if err != nil {
resp.WriteError(http.StatusInternalServerError, err)
return
}
resp.WriteAsJson(resJson[0])
return
}
resp.WriteAsJson(resJson)
}
func CheckCron(req *restful.Request, resp *restful.Response) {
res, err := devops.CheckCron(req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.WriteAsJson(res)
}
func GetPipelineRun(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
runId := req.PathParameter("runId")
res, err := devops.GetPipelineRun(projectName, pipelineName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func GetBranchPipe(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName")
res, err := devops.GetBranchPipe(projectName, pipelineName, branchName, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func GetPipeRunNodes(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
runId := req.PathParameter("runId")
res, err := devops.GetPipeRunNodes(projectName, pipelineName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func GetNodeSteps(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId")
nodeId := req.PathParameter("nodeId")
res, err := devops.GetNodeSteps(projectName, pipelineName, branchName, runId, nodeId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func ToJenkinsfile(req *restful.Request, resp *restful.Response) {
res, err := devops.ToJenkinsfile(req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func ToJson(req *restful.Request, resp *restful.Response) {
res, err := devops.ToJson(req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Write(res)
}
func parseErr(err error, resp *restful.Response) {
log.Error(err)
if jErr, ok := err.(*devops.JkError); ok {
_ = resp.WriteError(jErr.Code, err)
resp.WriteError(jErr.Code, err)
} else {
_ = resp.WriteError(http.StatusInternalServerError, err)
resp.WriteError(http.StatusInternalServerError, err)
}
return
}

View File

@@ -19,9 +19,9 @@ package devops
import (
"compress/gzip"
"encoding/json"
"flag"
"fmt"
"github.com/PuerkitoBio/goquery"
log "github.com/golang/glog"
"io"
"io/ioutil"
@@ -36,12 +36,11 @@ func init() {
flag.StringVar(&JenkinsUrl, "jenkins-url", "http://ks-jenkins.kubesphere-devops-system.svc.cluster.local:80", "jenkins server host")
}
func GetPipeline(projectName, pipelineName string, req *http.Request) (*Pipeline, error) {
func GetPipeline(projectName, pipelineName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipelineUrl, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl)
var res = new(Pipeline)
err := jenkinsClient(baseUrl, req, res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -50,12 +49,11 @@ func GetPipeline(projectName, pipelineName string, req *http.Request) (*Pipeline
return res, err
}
func SearchPipelines(req *http.Request) ([]interface{}, error) {
func SearchPipelines(req *http.Request) ([]byte, error) {
baseUrl := JenkinsUrl + SearchPipelineUrl + req.URL.RawQuery
log.Infof("Jenkins-url: " + baseUrl)
var res []interface{}
err := jenkinsClient(baseUrl, req, &res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -64,12 +62,11 @@ func SearchPipelines(req *http.Request) ([]interface{}, error) {
return res, err
}
func SearchPipelineRuns(projectName, pipelineName string, req *http.Request) ([]interface{}, error) {
func SearchPipelineRuns(projectName, pipelineName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+SearchPipelineRunUrl+req.URL.RawQuery, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl)
var res []interface{}
err := jenkinsClient(baseUrl, req, &res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -78,12 +75,11 @@ func SearchPipelineRuns(projectName, pipelineName string, req *http.Request) ([]
return res, err
}
func GetPipelineRun(projectName, pipelineName, branchName, runId string, req *http.Request) (*PipelineRun, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipelineRunUrl, projectName, pipelineName, branchName, runId)
func GetPipeBranchRun(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipeBranchRunUrl, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
var res = new(PipelineRun)
err := jenkinsClient(baseUrl, req, res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -92,12 +88,11 @@ func GetPipelineRun(projectName, pipelineName, branchName, runId string, req *ht
return res, err
}
func GetPipelineRunNodes(projectName, pipelineName, branchName, runId string, req *http.Request) ([]interface{}, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipelineRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
func GetBranchPipeRunNodes(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetBranchPipeRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
var res []interface{}
err := jenkinsClient(baseUrl, req, &res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -106,11 +101,11 @@ func GetPipelineRunNodes(projectName, pipelineName, branchName, runId string, re
return res, err
}
func GetStepLog(projectName, pipelineName, branchName, runId, stepId, nodeId string, req *http.Request) ([]byte, error) {
func GetStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetStepLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := Client(baseUrl, req)
resBody, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -123,7 +118,7 @@ func Validate(scmId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+ValidateUrl, scmId)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := Client(baseUrl, req)
resBody, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -132,12 +127,11 @@ func Validate(scmId string, req *http.Request) ([]byte, error) {
return resBody, err
}
func GetSCMOrg(scmId string, req *http.Request) ([]interface{}, error) {
func GetSCMOrg(scmId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetSCMOrgUrl+req.URL.RawQuery, scmId)
log.Infof("Jenkins-url: " + baseUrl)
var res []interface{}
err := jenkinsClient(baseUrl, req, &res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -146,12 +140,11 @@ func GetSCMOrg(scmId string, req *http.Request) ([]interface{}, error) {
return res, err
}
func GetOrgRepo(scmId, organizationId string, req *http.Request) (*OrgRepo, error) {
func GetOrgRepo(scmId, organizationId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetOrgRepoUrl+req.URL.RawQuery, scmId, organizationId)
log.Infof("Jenkins-url: " + baseUrl)
var res = new(OrgRepo)
err := jenkinsClient(baseUrl, req, res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -160,12 +153,11 @@ func GetOrgRepo(scmId, organizationId string, req *http.Request) (*OrgRepo, erro
return res, err
}
func StopPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) (*StopPipe, error) {
func StopPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+StopPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
var res = new(StopPipe)
err := jenkinsClient(baseUrl, req, res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -174,12 +166,11 @@ func StopPipeline(projectName, pipelineName, branchName, runId string, req *http
return res, err
}
func ReplayPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) (*ReplayPipe, error) {
func ReplayPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+ReplayPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
var res = new(ReplayPipe)
err := jenkinsClient(baseUrl, req, res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -192,21 +183,7 @@ func GetRunLog(projectName, pipelineName, branchName, runId string, req *http.Re
baseUrl := fmt.Sprintf(JenkinsUrl+GetRunLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := Client(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return resBody, err
}
func GetArtifacts(projectName, pipelineName, branchName, runId string, req *http.Request) ([]interface{}, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetArtifactsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
var res []interface{}
err := jenkinsClient(baseUrl, req, &res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -215,12 +192,24 @@ func GetArtifacts(projectName, pipelineName, branchName, runId string, req *http
return res, err
}
func GetPipeBranch(projectName, pipelineName string, req *http.Request) ([]interface{}, error) {
func GetArtifacts(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetArtifactsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
func GetPipeBranch(projectName, pipelineName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipeBranchUrl+req.URL.RawQuery, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl)
var res []interface{}
err := jenkinsClient(baseUrl, req, &res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -233,7 +222,7 @@ func CheckPipeline(projectName, pipelineName, branchName, runId, nodeId, stepId
baseUrl := fmt.Sprintf(JenkinsUrl+CheckPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := Client(baseUrl, req)
resBody, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -246,7 +235,7 @@ func GetConsoleLog(projectName, pipelineName string, req *http.Request) ([]byte,
baseUrl := fmt.Sprintf(JenkinsUrl+GetConsoleLogUrl+req.URL.RawQuery, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := Client(baseUrl, req)
resBody, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -259,7 +248,7 @@ func ScanBranch(projectName, pipelineName string, req *http.Request) ([]byte, er
baseUrl := fmt.Sprintf(JenkinsUrl+ScanBranchUrl+req.URL.RawQuery, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := Client(baseUrl, req)
resBody, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -268,12 +257,11 @@ func ScanBranch(projectName, pipelineName string, req *http.Request) ([]byte, er
return resBody, err
}
func RunPipeline(projectName, pipelineName, branchName string, req *http.Request) (*QueuedBlueRun, error) {
func RunPipeline(projectName, pipelineName, branchName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+RunPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName)
log.Infof("Jenkins-url: " + baseUrl)
var res = new(QueuedBlueRun)
err := jenkinsClient(baseUrl, req, res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -282,12 +270,11 @@ func RunPipeline(projectName, pipelineName, branchName string, req *http.Request
return res, err
}
func GetStepsStatus(projectName, pipelineName, branchName, runId, nodeId string, req *http.Request) (*NodeStatus, error) {
func GetStepsStatus(projectName, pipelineName, branchName, runId, nodeId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetStepsStatusUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId)
log.Infof("Jenkins-url: " + baseUrl)
var res = new(NodeStatus)
err := jenkinsClient(baseUrl, req, res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -296,12 +283,11 @@ func GetStepsStatus(projectName, pipelineName, branchName, runId, nodeId string,
return res, err
}
func GetCrumb(req *http.Request) (*Crumb, error) {
func GetCrumb(req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl + GetCrumbUrl)
log.Infof("Jenkins-url: " + baseUrl)
var res = new(Crumb)
err := jenkinsClient(baseUrl, req, res)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
@@ -310,25 +296,124 @@ func GetCrumb(req *http.Request) (*Crumb, error) {
return res, err
}
// jenkins request and parse response
func jenkinsClient(baseUrl string, req *http.Request, res interface{}) error {
resBody, err := Client(baseUrl, req)
func CheckScriptCompile(req *http.Request) ([]byte, error) {
baseUrl := JenkinsUrl + CheckScriptCompileUrl
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return err
return nil, err
}
err = json.Unmarshal(resBody, res)
if err != nil {
log.Error(err)
return err
}
return nil
return resBody, err
}
// create request
func Client(baseUrl string, req *http.Request) ([]byte, error) {
func CheckCron(req *http.Request) (*CheckCronRes, error) {
baseUrl := JenkinsUrl + CheckCronUrl + req.URL.RawQuery
log.Infof("Jenkins-url: " + baseUrl)
var res = new(CheckCronRes)
resp, err := http.Get(baseUrl)
if err != nil {
log.Error(err)
return res, err
}
defer resp.Body.Close()
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
log.Error(err)
return res, err
}
doc.Find("div").Each(func(i int, selection *goquery.Selection) {
res.Message = selection.Text()
res.Result, _ = selection.Attr("class")
})
return res, err
}
func GetPipelineRun(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipelineRunUrl, projectName, pipelineName, runId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
func GetBranchPipe(projectName, pipelineName, branchName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetBranchPipeUrl, projectName, pipelineName, branchName)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
func GetPipeRunNodes(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipeRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, runId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
func GetNodeSteps(projectName, pipelineName, branchName, runId, nodeId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetNodeStepsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId)
log.Infof("Jenkins-url: " + baseUrl)
//var res = new(NodeSteps)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
func ToJenkinsfile(req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl + ToJenkinsfileUrl)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
func ToJson(req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl + ToJsonUrl)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
// create jenkins request
func sendJenkinsRequest(baseUrl string, req *http.Request) ([]byte, error) {
newReqUrl, err := url.Parse(baseUrl)
if err != nil {
log.Error(err)
@@ -338,10 +423,12 @@ func Client(baseUrl string, req *http.Request) ([]byte, error) {
client := &http.Client{Timeout: 30 * time.Second}
newRequest := &http.Request{
Method: req.Method,
URL: newReqUrl,
Header: req.Header,
Body: req.Body,
Method: req.Method,
URL: newReqUrl,
Header: req.Header,
Body: req.Body,
Form: req.Form,
PostForm: req.PostForm,
}
resp, err := client.Do(newRequest)

View File

@@ -84,8 +84,8 @@ type Pipeline struct {
TotalNumberOfPullRequests int `json:"totalNumberOfPullRequests"`
}
// GetPipelineRun & SearchPipelineRuns
type PipelineRun struct {
// GetPipeBranchRun & SearchPipelineRuns
type PipeBranchRun struct {
Class string `json:"_class"`
Links struct {
PrevRun struct {
@@ -168,8 +168,8 @@ type PipelineRun struct {
PullRequest interface{} `json:"pullRequest"`
}
// GetPipelineRunNodes
type Nodes []struct {
// GetBranchPipeRunNodes
type BranchPipeRunNodes struct {
Class string `json:"_class"`
Links struct {
Self struct {
@@ -716,11 +716,12 @@ type NodeStatus []struct {
// CheckPipeline
type CheckPlayload struct {
ID string `json:"id"`
ID string `json:"id,omitempty"`
Parameters []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"parameters"`
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
} `json:"parameters,omitempty"`
Abort bool `json:"abort,omitempty"`
}
// Getcrumb
@@ -729,3 +730,329 @@ type Crumb struct {
Crumb string `json:"crumb"`
CrumbRequestField string `json:"crumbRequestField"`
}
// CheckScriptCompile
type CheckScript struct {
Column int `json:"column"`
Line int `json:"line"`
Message string `json:"message"`
Status string `json:"status"`
}
// CheckCron
type CheckCronRes struct {
Result string `json:"result"`
Message string `json:"message"`
}
// GetPipelineRun
type PipelineRun struct {
Class string `json:"_class"`
Links struct {
PrevRun struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"prevRun"`
Parent struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"parent"`
Tests struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"tests"`
Nodes struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"nodes"`
Log struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"log"`
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
BlueTestSummary struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"blueTestSummary"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
Steps struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"steps"`
Artifacts struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"artifacts"`
} `json:"_links"`
Actions []interface{} `json:"actions"`
ArtifactsZipFile interface{} `json:"artifactsZipFile"`
CauseOfBlockage interface{} `json:"causeOfBlockage"`
Causes []struct {
Class string `json:"_class"`
ShortDescription string `json:"shortDescription"`
UserID string `json:"userId"`
UserName string `json:"userName"`
} `json:"causes"`
ChangeSet []interface{} `json:"changeSet"`
Description interface{} `json:"description"`
DurationInMillis int `json:"durationInMillis"`
EnQueueTime string `json:"enQueueTime"`
EndTime string `json:"endTime"`
EstimatedDurationInMillis int `json:"estimatedDurationInMillis"`
ID string `json:"id"`
Name interface{} `json:"name"`
Organization string `json:"organization"`
Pipeline string `json:"pipeline"`
Replayable bool `json:"replayable"`
Result string `json:"result"`
RunSummary string `json:"runSummary"`
StartTime string `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
Branch interface{} `json:"branch"`
CommitID interface{} `json:"commitId"`
CommitURL interface{} `json:"commitUrl"`
PullRequest interface{} `json:"pullRequest"`
}
// GetBranchPipeRun
type BranchPipe struct {
Class string `json:"_class"`
Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
Scm struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"scm"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
Runs struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"runs"`
Trends struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"trends"`
Queue struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"queue"`
} `json:"_links"`
Actions []interface{} `json:"actions"`
Disabled bool `json:"disabled"`
DisplayName string `json:"displayName"`
EstimatedDurationInMillis int `json:"estimatedDurationInMillis"`
FullDisplayName string `json:"fullDisplayName"`
FullName string `json:"fullName"`
LatestRun struct {
Class string `json:"_class"`
Links struct {
PrevRun struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"prevRun"`
Parent struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"parent"`
Tests struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"tests"`
Log struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"log"`
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
BlueTestSummary struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"blueTestSummary"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
Artifacts struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"artifacts"`
} `json:"_links"`
Actions []interface{} `json:"actions"`
ArtifactsZipFile string `json:"artifactsZipFile"`
CauseOfBlockage interface{} `json:"causeOfBlockage"`
Causes []struct {
Class string `json:"_class"`
ShortDescription string `json:"shortDescription"`
UserID string `json:"userId"`
UserName string `json:"userName"`
} `json:"causes"`
ChangeSet []interface{} `json:"changeSet"`
Description interface{} `json:"description"`
DurationInMillis int `json:"durationInMillis"`
EnQueueTime string `json:"enQueueTime"`
EndTime string `json:"endTime"`
EstimatedDurationInMillis int `json:"estimatedDurationInMillis"`
ID string `json:"id"`
Name interface{} `json:"name"`
Organization string `json:"organization"`
Pipeline string `json:"pipeline"`
Replayable bool `json:"replayable"`
Result string `json:"result"`
RunSummary string `json:"runSummary"`
StartTime string `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
} `json:"latestRun"`
Name string `json:"name"`
Organization string `json:"organization"`
Parameters []struct {
Class string `json:"_class"`
DefaultParameterValue struct {
Class string `json:"_class"`
Name string `json:"name"`
Value string `json:"value"`
} `json:"defaultParameterValue"`
Description string `json:"description"`
Name string `json:"name"`
Type string `json:"type"`
} `json:"parameters"`
Permissions struct {
Create bool `json:"create"`
Configure bool `json:"configure"`
Read bool `json:"read"`
Start bool `json:"start"`
Stop bool `json:"stop"`
} `json:"permissions"`
WeatherScore int `json:"weatherScore"`
Branch struct {
IsPrimary bool `json:"isPrimary"`
Issues []interface{} `json:"issues"`
URL string `json:"url"`
} `json:"branch"`
}
// GetPipeRunNodes
type PipeRunNodes []struct {
Class string `json:"_class"`
Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
Steps struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"steps"`
} `json:"_links"`
Actions []interface{} `json:"actions"`
DisplayDescription interface{} `json:"displayDescription"`
DisplayName string `json:"displayName"`
DurationInMillis int `json:"durationInMillis"`
ID string `json:"id"`
Input interface{} `json:"input"`
Result string `json:"result"`
StartTime string `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
CauseOfBlockage interface{} `json:"causeOfBlockage"`
Edges []interface{} `json:"edges"`
FirstParent interface{} `json:"firstParent"`
Restartable bool `json:"restartable"`
}
// GetNodeSteps
type NodeSteps []struct {
Class string `json:"_class"`
Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
} `json:"_links"`
Actions []struct {
Class string `json:"_class"`
Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
} `json:"_links"`
URLName string `json:"urlName"`
} `json:"actions"`
DisplayDescription string `json:"displayDescription"`
DisplayName string `json:"displayName"`
DurationInMillis int `json:"durationInMillis"`
ID string `json:"id"`
Input interface{} `json:"input"`
Result string `json:"result"`
StartTime string `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
}
// ToJenkinsfile requests
type ReqJson struct {
Json string `json:"json"`
}
// ToJenkinsfile response
type ResJenkinsfile struct {
Status string `json:"status,omitempty"`
Data struct {
Result string `json:"result,omitempty"`
Jenkinsfile string `json:"jenkinsfile,omitempty"`
Errors []struct {
Location []string `json:"location,omitempty"`
Error string `json:"error,omitempty"`
} `json:"errors,omitempty"`
} `json:"data,omitempty"`
}
type ReqJenkinsfile struct {
Jenkinsfile string `json:"jenkinsfile"`
}
type ResJson struct {
Status string `json:"status,omitempty"`
Data struct {
Result string `json:"result,omitempty"`
JSON struct {
Pipeline struct {
Stages []interface{} `json:"stages,omitempty"`
Agent struct {
Type string `json:"type,omitempty"`
Arguments []struct {
Key string `json:"key,omitempty"`
Value struct {
IsLiteral bool `json:"isLiteral,omitempty"`
Value string `json:"value,omitempty"`
} `json:"value,omitempty"`
} `json:"arguments,omitempty"`
} `json:"agent,omitempty"`
} `json:"pipeline,omitempty"`
} `json:"json,omitempty"`
} `json:"data,omitempty"`
}

View File

@@ -19,24 +19,32 @@ package devops
// Some apis for Jenkins.
const (
GetPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/"
SearchPipelineUrl = "/blue/rest/search/?"
SearchPipelineRunUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/?"
GetPipelineRunUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/"
GetPipelineRunNodesUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/?"
GetStepLogUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/%s/log/?"
ValidateUrl = "/blue/rest/organizations/jenkins/scm/%s/validate"
GetSCMOrgUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/?"
GetOrgRepoUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/%s/repositories/?"
StopPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/stop/?"
ReplayPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/replay/"
GetRunLogUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/log/?"
GetArtifactsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/artifacts/?"
GetPipeBranchUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/?"
GetConsoleLogUrl = "/job/%s/job/%s/indexing/consoleText"
ScanBranchUrl = "/job/%s/job/%s/build?"
RunPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/"
GetStepsStatusUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?"
CheckPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/nodes/%s/steps/%s/"
GetCrumbUrl = "/crumbIssuer/api/json/"
GetPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/"
SearchPipelineUrl = "/blue/rest/search/?"
SearchPipelineRunUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/?"
GetPipeBranchRunUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/"
GetBranchPipeRunNodesUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/?"
GetStepLogUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/%s/log/?"
ValidateUrl = "/blue/rest/organizations/jenkins/scm/%s/validate"
GetSCMOrgUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/?"
GetOrgRepoUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/%s/repositories/?"
StopPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/stop/?"
ReplayPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/replay/"
GetRunLogUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/log/?"
GetArtifactsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/artifacts/?"
GetPipeBranchUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/?"
GetConsoleLogUrl = "/job/%s/job/%s/indexing/consoleText"
ScanBranchUrl = "/job/%s/job/%s/build?"
RunPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/"
GetStepsStatusUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?"
CheckPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/nodes/%s/steps/%s/"
GetCrumbUrl = "/crumbIssuer/api/json/"
CheckScriptCompileUrl = "/job/init-job/descriptorByName/org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition/checkScriptCompile"
CheckCronUrl = "/job/init-job/descriptorByName/hudson.triggers.TimerTrigger/checkSpec?"
GetPipelineRunUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/"
GetBranchPipeUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/"
GetPipeRunNodesUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/?"
GetNodeStepsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?"
ToJenkinsfileUrl = "/pipeline-model-converter/toJenkinsfile"
ToJsonUrl = "/pipeline-model-converter/toJson"
)