未验证 提交 0e50a93e 编写于 作者: 不羁 提交者: GitHub

Merge branch 'master' into master

...@@ -307,7 +307,7 @@ func addWebService(c *restful.Container) error { ...@@ -307,7 +307,7 @@ func addWebService(c *restful.Container) error {
// match "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log/?start=0" // 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"). webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log").
To(devopsapi.GetStepLog). To(devopsapi.GetBranchStepLog).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get pipelines step log."). Doc("Get pipelines step log.").
Produces("text/plain; charset=utf-8"). Produces("text/plain; charset=utf-8").
...@@ -322,6 +322,22 @@ func addWebService(c *restful.Container) error { ...@@ -322,6 +322,22 @@ func addWebService(c *restful.Container) error {
DataFormat("start=%d"). DataFormat("start=%d").
DefaultValue("start=0"))) DefaultValue("start=0")))
// match "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log/?start=0"
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log").
To(devopsapi.GetStepLog).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get pipelines step log.").
Produces("text/plain; charset=utf-8").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("runId", "pipeline runs id")).
Param(webservice.PathParameter("nodeId", "pipeline runs node id")).
Param(webservice.PathParameter("stepId", "pipeline runs step id")).
Param(webservice.QueryParameter("start", "start").
Required(true).
DataFormat("start=%d").
DefaultValue("start=0")))
// match "/blue/rest/organizations/jenkins/scm/github/validate/" // match "/blue/rest/organizations/jenkins/scm/github/validate/"
webservice.Route(webservice.PUT("/devops/scm/{scmId}/validate"). webservice.Route(webservice.PUT("/devops/scm/{scmId}/validate").
To(devopsapi.Validate). To(devopsapi.Validate).
...@@ -364,7 +380,7 @@ func addWebService(c *restful.Container) error { ...@@ -364,7 +380,7 @@ func addWebService(c *restful.Container) error {
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/stop/ // match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/stop/
webservice.Route(webservice.PUT("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/stop"). webservice.Route(webservice.PUT("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/stop").
To(devopsapi.StopPipeline). To(devopsapi.StopBranchPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Stop pipeline in running"). Doc("Stop pipeline in running").
Param(webservice.PathParameter("projectName", "devops project name")). Param(webservice.PathParameter("projectName", "devops project name")).
...@@ -382,9 +398,28 @@ func addWebService(c *restful.Container) error { ...@@ -382,9 +398,28 @@ func addWebService(c *restful.Container) error {
Returns(http.StatusOK, RespOK, devops.StopPipe{}). Returns(http.StatusOK, RespOK, devops.StopPipe{}).
Writes(devops.StopPipe{})) Writes(devops.StopPipe{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/runs/{runId}/stop/
webservice.Route(webservice.PUT("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/stop").
To(devopsapi.StopPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Stop pipeline in running").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("runId", "pipeline runs id")).
Param(webservice.QueryParameter("blocking", "stop and between each retries will sleep").
Required(false).
DataFormat("blocking=%t").
DefaultValue("blocking=false")).
Param(webservice.QueryParameter("timeOutInSecs", "the time of stop and between each retries sleep").
Required(false).
DataFormat("timeOutInSecs=%d").
DefaultValue("timeOutInSecs=10")).
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"). webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/replay").
To(devopsapi.ReplayPipeline). To(devopsapi.ReplayBranchPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Replay pipeline"). Doc("Replay pipeline").
Param(webservice.PathParameter("projectName", "devops project name")). Param(webservice.PathParameter("projectName", "devops project name")).
...@@ -394,9 +429,20 @@ func addWebService(c *restful.Container) error { ...@@ -394,9 +429,20 @@ func addWebService(c *restful.Container) error {
Returns(http.StatusOK, RespOK, devops.ReplayPipe{}). Returns(http.StatusOK, RespOK, devops.ReplayPipe{}).
Writes(devops.ReplayPipe{})) Writes(devops.ReplayPipe{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/runs/{runId}/Replay/
webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/replay").
To(devopsapi.ReplayPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Replay pipeline").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("runId", "pipeline runs id")).
Returns(http.StatusOK, RespOK, devops.ReplayPipe{}).
Writes(devops.ReplayPipe{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/log/?start=0 // match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/log/?start=0
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/log"). webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/log").
To(devopsapi.GetRunLog). To(devopsapi.GetBranchRunLog).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get Pipelines run log."). Doc("Get Pipelines run log.").
Produces("text/plain; charset=utf-8"). Produces("text/plain; charset=utf-8").
...@@ -409,9 +455,23 @@ func addWebService(c *restful.Container) error { ...@@ -409,9 +455,23 @@ func addWebService(c *restful.Container) error {
DataFormat("start=%d"). DataFormat("start=%d").
DefaultValue("start=0"))) DefaultValue("start=0")))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/log/?start=0
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/log").
To(devopsapi.GetRunLog).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get Pipelines run log.").
Produces("text/plain; charset=utf-8").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("runId", "pipeline runs id")).
Param(webservice.QueryParameter("start", "start").
Required(true).
DataFormat("start=%d").
DefaultValue("start=0")))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/artifacts // match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/artifacts
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/artifacts"). webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/artifacts").
To(devopsapi.GetArtifacts). To(devopsapi.GetBranchArtifacts).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get pipeline artifacts."). Doc("Get pipeline artifacts.").
Param(webservice.PathParameter("projectName", "devops project name")). Param(webservice.PathParameter("projectName", "devops project name")).
...@@ -427,6 +487,23 @@ func addWebService(c *restful.Container) error { ...@@ -427,6 +487,23 @@ func addWebService(c *restful.Container) error {
Returns(http.StatusOK, "The filed of \"Url\" in response can download artifacts", []devops.Artifacts{}). Returns(http.StatusOK, "The filed of \"Url\" in response can download artifacts", []devops.Artifacts{}).
Writes([]devops.Artifacts{})) Writes([]devops.Artifacts{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/artifacts
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/artifacts").
To(devopsapi.GetArtifacts).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get pipeline artifacts.").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("runId", "pipeline runs id")).
Param(webservice.QueryParameter("start", "start page").
Required(false).
DataFormat("start=%d")).
Param(webservice.QueryParameter("limit", "limit count").
Required(false).
DataFormat("limit=%d")).
Returns(http.StatusOK, "The filed of \"Url\" in response can download artifacts", []devops.Artifacts{}).
Writes([]devops.Artifacts{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/?filter=&start&limit= // match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/?filter=&start&limit=
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches"). webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches").
To(devopsapi.GetPipeBranch). To(devopsapi.GetPipeBranch).
...@@ -448,7 +525,7 @@ func addWebService(c *restful.Container) error { ...@@ -448,7 +525,7 @@ func addWebService(c *restful.Container) error {
// /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId} // /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}
webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}"). webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}").
To(devopsapi.CheckPipeline). To(devopsapi.CheckBranchPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Pauses pipeline execution and allows the user to interact and control the flow of the build."). Doc("Pauses pipeline execution and allows the user to interact and control the flow of the build.").
Reads(devops.CheckPlayload{}). Reads(devops.CheckPlayload{}).
...@@ -460,6 +537,19 @@ func addWebService(c *restful.Container) error { ...@@ -460,6 +537,19 @@ func addWebService(c *restful.Container) error {
Param(webservice.PathParameter("nodeId", "pipeline node id")). Param(webservice.PathParameter("nodeId", "pipeline node id")).
Param(webservice.PathParameter("stepId", "pipeline step id"))) Param(webservice.PathParameter("stepId", "pipeline step id")))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}
webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}").
To(devopsapi.CheckPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Pauses pipeline execution and allows the user to interact and control the flow of the build.").
Reads(devops.CheckPlayload{}).
Produces("text/plain; charset=utf-8").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("runId", "pipeline runs id")).
Param(webservice.PathParameter("nodeId", "pipeline node id")).
Param(webservice.PathParameter("stepId", "pipeline step id")))
// match /job/project-8QnvykoJw4wZ/job/test-1/indexing/consoleText // match /job/project-8QnvykoJw4wZ/job/test-1/indexing/consoleText
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/console/log"). webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/console/log").
To(devopsapi.GetConsoleLog). To(devopsapi.GetConsoleLog).
...@@ -495,7 +585,7 @@ func addWebService(c *restful.Container) error { ...@@ -495,7 +585,7 @@ func addWebService(c *restful.Container) error {
// match /pipeline_status/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/?limit= // match /pipeline_status/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/?limit=
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/status"). webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/status").
To(devopsapi.GetStepsStatus). To(devopsapi.GetBranchStepsStatus).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get pipeline steps status."). Doc("Get pipeline steps status.").
Param(webservice.PathParameter("projectName", "devops project name")). Param(webservice.PathParameter("projectName", "devops project name")).
...@@ -509,6 +599,21 @@ func addWebService(c *restful.Container) error { ...@@ -509,6 +599,21 @@ func addWebService(c *restful.Container) error {
Returns(http.StatusOK, RespOK, []devops.QueuedBlueRun{}). Returns(http.StatusOK, RespOK, []devops.QueuedBlueRun{}).
Writes([]devops.QueuedBlueRun{})) Writes([]devops.QueuedBlueRun{}))
// match /pipeline_status/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/nodes/?limit=
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/status").
To(devopsapi.GetStepsStatus).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get pipeline steps status.").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("runId", "pipeline run name")).
Param(webservice.PathParameter("nodeId", "pipeline node id")).
Param(webservice.QueryParameter("limit", "limit count").
Required(true).
DataFormat("limit=%d")).
Returns(http.StatusOK, RespOK, []devops.QueuedBlueRun{}).
Writes([]devops.QueuedBlueRun{}))
// match /crumbIssuer/api/json/ // match /crumbIssuer/api/json/
webservice.Route(webservice.GET("/devops/crumbissuer"). webservice.Route(webservice.GET("/devops/crumbissuer").
To(devopsapi.GetCrumb). To(devopsapi.GetCrumb).
...@@ -579,7 +684,7 @@ func addWebService(c *restful.Container) error { ...@@ -579,7 +684,7 @@ func addWebService(c *restful.Container) error {
// match /blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?limit= // 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"). webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps").
To(devopsapi.GetNodeSteps). To(devopsapi.GetBranchNodeSteps).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get steps in node."). Doc("Get steps in node.").
Param(webservice.PathParameter("projectName", "devops project name")). Param(webservice.PathParameter("projectName", "devops project name")).
...@@ -587,6 +692,21 @@ func addWebService(c *restful.Container) error { ...@@ -587,6 +692,21 @@ func addWebService(c *restful.Container) error {
Param(webservice.PathParameter("branchName", "pipeline branch name")). Param(webservice.PathParameter("branchName", "pipeline branch name")).
Param(webservice.PathParameter("runId", "pipeline run id")). Param(webservice.PathParameter("runId", "pipeline run id")).
Param(webservice.PathParameter("nodeId", "pipeline node 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 /blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/%s/steps/?limit=
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/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("runId", "pipeline run id")).
Param(webservice.PathParameter("nodeId", "pipeline node id")).
Param(webservice.QueryParameter("limit", "limit count"). Param(webservice.QueryParameter("limit", "limit count").
Required(false). Required(false).
DataFormat("limit=%d")). DataFormat("limit=%d")).
...@@ -601,7 +721,7 @@ func addWebService(c *restful.Container) error { ...@@ -601,7 +721,7 @@ func addWebService(c *restful.Container) error {
Produces("application/json", "charset=utf-8"). Produces("application/json", "charset=utf-8").
Doc("Json to Jenkinsfile."). Doc("Json to Jenkinsfile.").
Reads(devops.ReqJson{}). Reads(devops.ReqJson{}).
Returns(http.StatusOK, RespOK,devops.NodeSteps{}). Returns(http.StatusOK, RespOK, devops.NodeSteps{}).
Writes(devops.ResJenkinsfile{})) Writes(devops.ResJenkinsfile{}))
// match /pipeline-model-converter/toJson // match /pipeline-model-converter/toJson
...@@ -612,7 +732,7 @@ func addWebService(c *restful.Container) error { ...@@ -612,7 +732,7 @@ func addWebService(c *restful.Container) error {
Produces("application/json", "charset=utf-8"). Produces("application/json", "charset=utf-8").
Doc("Jenkinsfile to Json."). Doc("Jenkinsfile to Json.").
Reads(devops.ReqJenkinsfile{}). Reads(devops.ReqJenkinsfile{}).
Returns(http.StatusOK, RespOK,devops.ResJson{}). Returns(http.StatusOK, RespOK, devops.ResJson{}).
Writes(devops.ResJson{})) Writes(devops.ResJson{}))
// match /git/notifyCommit/?url= // match /git/notifyCommit/?url=
...@@ -641,6 +761,36 @@ func addWebService(c *restful.Container) error { ...@@ -641,6 +761,36 @@ func addWebService(c *restful.Container) error {
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("receive webhook request.")) Doc("receive webhook request."))
// in scm get all steps in nodes.
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodesdetail").
To(devopsapi.GetBranchNodesDetail).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get pipeline nodes stages detail").
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")).
Param(webservice.PathParameter("runId", "pipeline runs id")).
Param(webservice.QueryParameter("limit", "limit count").
Required(true).
DataFormat("limit=%d")).
Returns(http.StatusOK, RespOK,[]devops.NodesDetail{}).
Writes(devops.NodesDetail{}))
// out of scm get all steps in nodes.
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodesdetail").
To(devopsapi.GetNodesDetail).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get pipeline nodes stages detail").
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")).
Param(webservice.PathParameter("runId", "pipeline runs id")).
Param(webservice.QueryParameter("limit", "limit count").
Required(true).
DataFormat("limit=%d")).
Returns(http.StatusOK, RespOK,[]devops.NodesDetail{}).
Writes(devops.NodesDetail{}))
c.Add(webservice) c.Add(webservice)
return nil return nil
......
...@@ -96,7 +96,7 @@ func GetPipelineRunNodesbyBranch(req *restful.Request, resp *restful.Response) { ...@@ -96,7 +96,7 @@ func GetPipelineRunNodesbyBranch(req *restful.Request, resp *restful.Response) {
resp.Write(res) resp.Write(res)
} }
func GetStepLog(req *restful.Request, resp *restful.Response) { func GetBranchStepLog(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName") projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName") pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName") branchName := req.PathParameter("branchName")
...@@ -104,7 +104,22 @@ func GetStepLog(req *restful.Request, resp *restful.Response) { ...@@ -104,7 +104,22 @@ func GetStepLog(req *restful.Request, resp *restful.Response) {
nodeId := req.PathParameter("nodeId") nodeId := req.PathParameter("nodeId")
stepId := req.PathParameter("stepId") stepId := req.PathParameter("stepId")
res, err := devops.GetStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId, req.Request) res, err := devops.GetBranchStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Write(res)
}
func GetStepLog(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
runId := req.PathParameter("runId")
nodeId := req.PathParameter("nodeId")
stepId := req.PathParameter("stepId")
res, err := devops.GetStepLog(projectName, pipelineName, runId, nodeId, stepId, req.Request)
if err != nil { if err != nil {
parseErr(err, resp) parseErr(err, resp)
return return
...@@ -152,13 +167,44 @@ func GetOrgRepo(req *restful.Request, resp *restful.Response) { ...@@ -152,13 +167,44 @@ func GetOrgRepo(req *restful.Request, resp *restful.Response) {
resp.Write(res) resp.Write(res)
} }
func StopBranchPipeline(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.StopBranchPipeline(projectName, pipelineName, branchName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func StopPipeline(req *restful.Request, resp *restful.Response) { func StopPipeline(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
runId := req.PathParameter("runId")
res, err := devops.StopPipeline(projectName, pipelineName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func ReplayBranchPipeline(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName") projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName") pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName") branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId") runId := req.PathParameter("runId")
res, err := devops.StopPipeline(projectName, pipelineName, branchName, runId, req.Request) res, err := devops.ReplayBranchPipeline(projectName, pipelineName, branchName, runId, req.Request)
if err != nil { if err != nil {
parseErr(err, resp) parseErr(err, resp)
return return
...@@ -171,10 +217,9 @@ func StopPipeline(req *restful.Request, resp *restful.Response) { ...@@ -171,10 +217,9 @@ func StopPipeline(req *restful.Request, resp *restful.Response) {
func ReplayPipeline(req *restful.Request, resp *restful.Response) { func ReplayPipeline(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName") projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName") pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId") runId := req.PathParameter("runId")
res, err := devops.ReplayPipeline(projectName, pipelineName, branchName, runId, req.Request) res, err := devops.ReplayPipeline(projectName, pipelineName, runId, req.Request)
if err != nil { if err != nil {
parseErr(err, resp) parseErr(err, resp)
return return
...@@ -184,13 +229,13 @@ func ReplayPipeline(req *restful.Request, resp *restful.Response) { ...@@ -184,13 +229,13 @@ func ReplayPipeline(req *restful.Request, resp *restful.Response) {
resp.Write(res) resp.Write(res)
} }
func GetRunLog(req *restful.Request, resp *restful.Response) { func GetBranchRunLog(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName") projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName") pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName") branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId") runId := req.PathParameter("runId")
res, err := devops.GetRunLog(projectName, pipelineName, branchName, runId, req.Request) res, err := devops.GetBranchRunLog(projectName, pipelineName, branchName, runId, req.Request)
if err != nil { if err != nil {
parseErr(err, resp) parseErr(err, resp)
return return
...@@ -199,13 +244,41 @@ func GetRunLog(req *restful.Request, resp *restful.Response) { ...@@ -199,13 +244,41 @@ func GetRunLog(req *restful.Request, resp *restful.Response) {
resp.Write(res) resp.Write(res)
} }
func GetArtifacts(req *restful.Request, resp *restful.Response) { func GetRunLog(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
runId := req.PathParameter("runId")
res, err := devops.GetRunLog(projectName, pipelineName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Write(res)
}
func GetBranchArtifacts(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName") projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName") pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName") branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId") runId := req.PathParameter("runId")
res, err := devops.GetArtifacts(projectName, pipelineName, branchName, runId, req.Request) res, err := devops.GetBranchArtifacts(projectName, pipelineName, branchName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func GetArtifacts(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
runId := req.PathParameter("runId")
res, err := devops.GetArtifacts(projectName, pipelineName, runId, req.Request)
if err != nil { if err != nil {
parseErr(err, resp) parseErr(err, resp)
return return
...@@ -227,7 +300,7 @@ func GetPipeBranch(req *restful.Request, resp *restful.Response) { ...@@ -227,7 +300,7 @@ func GetPipeBranch(req *restful.Request, resp *restful.Response) {
resp.Write(res) resp.Write(res)
} }
func CheckPipeline(req *restful.Request, resp *restful.Response) { func CheckBranchPipeline(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName") projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName") pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName") branchName := req.PathParameter("branchName")
...@@ -235,7 +308,23 @@ func CheckPipeline(req *restful.Request, resp *restful.Response) { ...@@ -235,7 +308,23 @@ func CheckPipeline(req *restful.Request, resp *restful.Response) {
nodeId := req.PathParameter("nodeId") nodeId := req.PathParameter("nodeId")
stepId := req.PathParameter("stepId") stepId := req.PathParameter("stepId")
res, err := devops.CheckPipeline(projectName, pipelineName, branchName, runId, nodeId, stepId, req.Request) res, err := devops.CheckBranchPipeline(projectName, pipelineName, branchName, runId, nodeId, stepId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Write(res)
}
func CheckPipeline(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
runId := req.PathParameter("runId")
nodeId := req.PathParameter("nodeId")
stepId := req.PathParameter("stepId")
res, err := devops.CheckPipeline(projectName, pipelineName, runId, nodeId, stepId, req.Request)
if err != nil { if err != nil {
parseErr(err, resp) parseErr(err, resp)
return return
...@@ -285,14 +374,30 @@ func RunPipeline(req *restful.Request, resp *restful.Response) { ...@@ -285,14 +374,30 @@ func RunPipeline(req *restful.Request, resp *restful.Response) {
resp.Write(res) resp.Write(res)
} }
func GetStepsStatus(req *restful.Request, resp *restful.Response) { func GetBranchStepsStatus(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName") projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName") pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName") branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId") runId := req.PathParameter("runId")
nodeId := req.PathParameter("nodeId") nodeId := req.PathParameter("nodeId")
res, err := devops.GetStepsStatus(projectName, pipelineName, branchName, runId, nodeId, req.Request) res, err := devops.GetBranchStepsStatus(projectName, pipelineName, branchName, runId, nodeId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func GetStepsStatus(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
runId := req.PathParameter("runId")
nodeId := req.PathParameter("nodeId")
res, err := devops.GetStepsStatus(projectName, pipelineName, runId, nodeId, req.Request)
if err != nil { if err != nil {
parseErr(err, resp) parseErr(err, resp)
return return
...@@ -392,14 +497,29 @@ func GetPipelineRunNodes(req *restful.Request, resp *restful.Response) { ...@@ -392,14 +497,29 @@ func GetPipelineRunNodes(req *restful.Request, resp *restful.Response) {
resp.Write(res) resp.Write(res)
} }
func GetNodeSteps(req *restful.Request, resp *restful.Response) { func GetBranchNodeSteps(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName") projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName") pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName") branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId") runId := req.PathParameter("runId")
nodeId := req.PathParameter("nodeId") nodeId := req.PathParameter("nodeId")
res, err := devops.GetNodeSteps(projectName, pipelineName, branchName, runId, nodeId, req.Request) res, err := devops.GetBranchNodeSteps(projectName, pipelineName, branchName, runId, nodeId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func GetNodeSteps(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
runId := req.PathParameter("runId")
nodeId := req.PathParameter("nodeId")
res, err := devops.GetNodeSteps(projectName, pipelineName, runId, nodeId, req.Request)
if err != nil { if err != nil {
parseErr(err, resp) parseErr(err, resp)
return return
...@@ -446,6 +566,33 @@ func GithubWebhook(req *restful.Request, resp *restful.Response) { ...@@ -446,6 +566,33 @@ func GithubWebhook(req *restful.Request, resp *restful.Response) {
resp.Write(res) resp.Write(res)
} }
func GetBranchNodesDetail(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.GetBranchNodesDetail(projectName, pipelineName, branchName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.WriteAsJson(res)
}
func GetNodesDetail(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
runId := req.PathParameter("runId")
res, err := devops.GetNodesDetail(projectName, pipelineName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.WriteAsJson(res)
}
func parseErr(err error, resp *restful.Response) { func parseErr(err error, resp *restful.Response) {
log.Error(err) log.Error(err)
if jErr, ok := err.(*devops.JkError); ok { if jErr, ok := err.(*devops.JkError); ok {
......
...@@ -19,6 +19,7 @@ package devops ...@@ -19,6 +19,7 @@ package devops
import ( import (
"compress/gzip" "compress/gzip"
"encoding/json"
"fmt" "fmt"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
log "github.com/golang/glog" log "github.com/golang/glog"
...@@ -28,9 +29,12 @@ import ( ...@@ -28,9 +29,12 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/admin_jenkins" "kubesphere.io/kubesphere/pkg/simple/client/admin_jenkins"
"net/http" "net/http"
"net/url" "net/url"
"sync"
"time" "time"
) )
const channelMaxCapacity = 100
var jenkins *gojenkins.Jenkins var jenkins *gojenkins.Jenkins
func PreCheckJenkins() { func PreCheckJenkins() {
...@@ -102,8 +106,21 @@ func GetPipelineRunNodesbyBranch(projectName, pipelineName, branchName, runId st ...@@ -102,8 +106,21 @@ func GetPipelineRunNodesbyBranch(projectName, pipelineName, branchName, runId st
return res, err return res, err
} }
func GetStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId string, req *http.Request) ([]byte, error) { func GetBranchStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+GetStepLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId) baseUrl := fmt.Sprintf(jenkins.Server+GetBranchStepLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return resBody, err
}
func GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+GetStepLogUrl+req.URL.RawQuery, projectName, pipelineName, runId, nodeId, stepId)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
resBody, err := sendJenkinsRequest(baseUrl, req) resBody, err := sendJenkinsRequest(baseUrl, req)
...@@ -154,8 +171,21 @@ func GetOrgRepo(scmId, organizationId string, req *http.Request) ([]byte, error) ...@@ -154,8 +171,21 @@ func GetOrgRepo(scmId, organizationId string, req *http.Request) ([]byte, error)
return res, err return res, err
} }
func StopPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) { func StopBranchPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+StopPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId) baseUrl := fmt.Sprintf(jenkins.Server+StopBranchPipelineUrl+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 StopPipeline(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+StopPipelineUrl+req.URL.RawQuery, projectName, pipelineName, runId)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req) res, err := sendJenkinsRequest(baseUrl, req)
...@@ -167,8 +197,8 @@ func StopPipeline(projectName, pipelineName, branchName, runId string, req *http ...@@ -167,8 +197,8 @@ func StopPipeline(projectName, pipelineName, branchName, runId string, req *http
return res, err return res, err
} }
func ReplayPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) { func ReplayBranchPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+ReplayPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId) baseUrl := fmt.Sprintf(jenkins.Server+ReplayBranchPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req) res, err := sendJenkinsRequest(baseUrl, req)
...@@ -180,8 +210,8 @@ func ReplayPipeline(projectName, pipelineName, branchName, runId string, req *ht ...@@ -180,8 +210,8 @@ func ReplayPipeline(projectName, pipelineName, branchName, runId string, req *ht
return res, err return res, err
} }
func GetRunLog(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) { func ReplayPipeline(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+GetRunLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId) baseUrl := fmt.Sprintf(jenkins.Server+ReplayPipelineUrl+req.URL.RawQuery, projectName, pipelineName, runId)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req) res, err := sendJenkinsRequest(baseUrl, req)
...@@ -193,8 +223,47 @@ func GetRunLog(projectName, pipelineName, branchName, runId string, req *http.Re ...@@ -193,8 +223,47 @@ func GetRunLog(projectName, pipelineName, branchName, runId string, req *http.Re
return res, err return res, err
} }
func GetArtifacts(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) { func GetBranchRunLog(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+GetArtifactsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId) baseUrl := fmt.Sprintf(jenkins.Server+GetBranchRunLogUrl+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 GetRunLog(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+GetRunLogUrl+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 GetBranchArtifacts(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+GetBranchArtifactsUrl+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 GetArtifacts(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+GetArtifactsUrl+req.URL.RawQuery, projectName, pipelineName, runId)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req) res, err := sendJenkinsRequest(baseUrl, req)
...@@ -219,8 +288,21 @@ func GetPipeBranch(projectName, pipelineName string, req *http.Request) ([]byte, ...@@ -219,8 +288,21 @@ func GetPipeBranch(projectName, pipelineName string, req *http.Request) ([]byte,
return res, err return res, err
} }
func CheckPipeline(projectName, pipelineName, branchName, runId, nodeId, stepId string, req *http.Request) ([]byte, error) { func CheckBranchPipeline(projectName, pipelineName, branchName, runId, nodeId, stepId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+CheckPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId) baseUrl := fmt.Sprintf(jenkins.Server+CheckBranchPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return resBody, err
}
func CheckPipeline(projectName, pipelineName, runId, nodeId, stepId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+CheckPipelineUrl+req.URL.RawQuery, projectName, pipelineName, runId, nodeId, stepId)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
resBody, err := sendJenkinsRequest(baseUrl, req) resBody, err := sendJenkinsRequest(baseUrl, req)
...@@ -271,8 +353,21 @@ func RunPipeline(projectName, pipelineName, branchName string, req *http.Request ...@@ -271,8 +353,21 @@ func RunPipeline(projectName, pipelineName, branchName string, req *http.Request
return res, err return res, err
} }
func GetStepsStatus(projectName, pipelineName, branchName, runId, nodeId string, req *http.Request) ([]byte, error) { func GetBranchStepsStatus(projectName, pipelineName, branchName, runId, nodeId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+GetStepsStatusUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId) baseUrl := fmt.Sprintf(jenkins.Server+GetBranchStepsStatusUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
func GetStepsStatus(projectName, pipelineName, runId, nodeId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+GetStepsStatusUrl+req.URL.RawQuery, projectName, pipelineName, runId, nodeId)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req) res, err := sendJenkinsRequest(baseUrl, req)
...@@ -375,8 +470,21 @@ func GetPipelineRunNodes(projectName, pipelineName, runId string, req *http.Requ ...@@ -375,8 +470,21 @@ func GetPipelineRunNodes(projectName, pipelineName, runId string, req *http.Requ
return res, err return res, err
} }
func GetNodeSteps(projectName, pipelineName, branchName, runId, nodeId string, req *http.Request) ([]byte, error) { func GetBranchNodeSteps(projectName, pipelineName, branchName, runId, nodeId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+GetNodeStepsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId) baseUrl := fmt.Sprintf(jenkins.Server+GetBranchNodeStepsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId)
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, runId, nodeId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+GetNodeStepsUrl+req.URL.RawQuery, projectName, pipelineName, runId, nodeId)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req) res, err := sendJenkinsRequest(baseUrl, req)
...@@ -441,6 +549,100 @@ func GithubWebhook(req *http.Request) ([]byte, error) { ...@@ -441,6 +549,100 @@ func GithubWebhook(req *http.Request) ([]byte, error) {
return res, err return res, err
} }
func GetBranchNodesDetail(projectName, pipelineName, branchName, runId string, req *http.Request) ([]NodesDetail, error) {
getNodesUrl := fmt.Sprintf(jenkins.Server+GetBranchPipeRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("getNodesUrl: " + getNodesUrl)
var wg sync.WaitGroup
var nodesDetails []NodesDetail
stepChan := make(chan *NodesStepsIndex, channelMaxCapacity)
respNodes, err := GetPipelineRunNodesbyBranch(projectName, pipelineName, branchName, runId, req)
if err != nil {
log.Error(err)
return nil, err
}
err = json.Unmarshal(respNodes, &nodesDetails)
if err != nil {
log.Error(err)
return nil, err
}
// get all steps in nodes.
for i, v := range nodesDetails {
wg.Add(1)
go func(nodeId string, index int) {
var steps []NodeSteps
respSteps, err := GetBranchNodeSteps(projectName, pipelineName, branchName, runId, nodeId, req)
if err != nil {
log.Error(err)
return
}
err = json.Unmarshal(respSteps, &steps)
stepChan <- &NodesStepsIndex{index, steps}
wg.Done()
}(v.ID, i)
}
wg.Wait()
close(stepChan)
for oneNodeSteps := range stepChan {
if oneNodeSteps != nil {
nodesDetails[oneNodeSteps.Id].Steps = append(nodesDetails[oneNodeSteps.Id].Steps, oneNodeSteps.Steps...)
}
}
return nodesDetails, err
}
func GetNodesDetail(projectName, pipelineName, runId string, req *http.Request) ([]NodesDetail, error) {
getNodesUrl := fmt.Sprintf(jenkins.Server+GetPipeRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, runId)
log.Infof("getNodesUrl: " + getNodesUrl)
var wg sync.WaitGroup
var nodesDetails []NodesDetail
stepChan := make(chan *NodesStepsIndex, channelMaxCapacity)
respNodes, err := GetPipelineRunNodes(projectName, pipelineName, runId, req)
if err != nil {
log.Error(err)
return nil, err
}
err = json.Unmarshal(respNodes, &nodesDetails)
if err != nil {
log.Error(err)
return nil, err
}
// get all steps in nodes.
for i, v := range nodesDetails {
wg.Add(1)
go func(nodeId string, index int) {
var steps []NodeSteps
respSteps, err := GetNodeSteps(projectName, pipelineName, runId, nodeId, req)
if err != nil {
log.Error(err)
return
}
err = json.Unmarshal(respSteps, &steps)
stepChan <- &NodesStepsIndex{index, steps}
wg.Done()
}(v.ID, i)
}
wg.Wait()
close(stepChan)
for oneNodeSteps := range stepChan {
if oneNodeSteps != nil {
nodesDetails[oneNodeSteps.Id].Steps = append(nodesDetails[oneNodeSteps.Id].Steps, oneNodeSteps.Steps...)
}
}
return nodesDetails, err
}
// create jenkins request // create jenkins request
func sendJenkinsRequest(baseUrl string, req *http.Request) ([]byte, error) { func sendJenkinsRequest(baseUrl string, req *http.Request) ([]byte, error) {
newReqUrl, err := url.Parse(baseUrl) newReqUrl, err := url.Parse(baseUrl)
......
...@@ -946,7 +946,7 @@ type BranchPipeline struct { ...@@ -946,7 +946,7 @@ type BranchPipeline struct {
} `json:"branch,omitempty"` } `json:"branch,omitempty"`
} }
// GetPipeRunNodes // GetPipelineRunNodes
type PipelineRunNodes struct { type PipelineRunNodes struct {
Class string `json:"_class,omitempty"` Class string `json:"_class,omitempty"`
Links struct { Links struct {
...@@ -1056,3 +1056,45 @@ type ResJson struct { ...@@ -1056,3 +1056,45 @@ type ResJson struct {
} `json:"json,omitempty"` } `json:"json,omitempty"`
} `json:"data,omitempty"` } `json:"data,omitempty"`
} }
type NodesDetail struct {
Class string `json:"_class,omitempty"`
Links struct {
Self struct {
Class string `json:"_class,omitempty"`
Href string `json:"href,omitempty"`
} `json:"self,omitempty"`
Actions struct {
Class string `json:"_class,omitempty"`
Href string `json:"href,omitempty"`
} `json:"actions,omitempty"`
Steps struct {
Class string `json:"_class,omitempty"`
Href string `json:"href,omitempty"`
} `json:"steps,omitempty"`
} `json:"_links,omitempty"`
Actions []interface{} `json:"actions,omitempty"`
DisplayDescription interface{} `json:"displayDescription,omitempty"`
DisplayName string `json:"displayName,omitempty"`
DurationInMillis int `json:"durationInMillis,omitempty"`
ID string `json:"id,omitempty"`
Input interface{} `json:"input,omitempty"`
Result string `json:"result,omitempty"`
StartTime string `json:"startTime,omitempty"`
State string `json:"state,omitempty"`
Type string `json:"type,omitempty"`
CauseOfBlockage interface{} `json:"causeOfBlockage,omitempty"`
Edges []struct {
Class string `json:"_class,omitempty"`
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
} `json:"edges,omitempty"`
FirstParent interface{} `json:"firstParent,omitempty"`
Restartable bool `json:"restartable,omitempty"`
Steps []NodeSteps `json:"steps,omitempty"`
}
type NodesStepsIndex struct {
Id int `json:"id,omitempty"`
Steps []NodeSteps `json:"steps,omitempty"`
}
...@@ -19,32 +19,40 @@ package devops ...@@ -19,32 +19,40 @@ package devops
// Some apis for Jenkins. // Some apis for Jenkins.
const ( const (
GetPipeBranchUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/?"
GetBranchPipeUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/"
GetPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/" GetPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/"
SearchPipelineUrl = "/blue/rest/search/?" SearchPipelineUrl = "/blue/rest/search/?"
SearchPipelineRunUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/?" RunPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/"
GetPipelineRunUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/"
GetPipeBranchRunUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/" GetPipeBranchRunUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/"
SearchPipelineRunUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/?"
GetBranchPipeRunNodesUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/?" 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/?" GetPipeRunNodesUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/?"
GetBranchRunLogUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/log/?"
GetRunLogUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/log/?"
GetBranchStepLogUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/%s/log/?"
GetStepLogUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/%s/steps/%s/log/?"
StopBranchPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/stop/?"
StopPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/runs/%s/stop/?"
ReplayBranchPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/replay/"
ReplayPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/runs/%s/replay/"
GetBranchArtifactsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/artifacts/?"
GetArtifactsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/artifacts/?"
GetBranchStepsStatusUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?"
GetStepsStatusUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/%s/steps/?"
CheckBranchPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/nodes/%s/steps/%s/"
CheckPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/runs/%s/nodes/%s/steps/%s/"
GetBranchNodeStepsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?"
GetNodeStepsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/%s/steps/?"
ValidateUrl = "/blue/rest/organizations/jenkins/scm/%s/validate" ValidateUrl = "/blue/rest/organizations/jenkins/scm/%s/validate"
GetSCMOrgUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/?" GetSCMOrgUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/?"
GetOrgRepoUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/%s/repositories/?" 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" GetConsoleLogUrl = "/job/%s/job/%s/indexing/consoleText"
ScanBranchUrl = "/job/%s/job/%s/build?" 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/" GetCrumbUrl = "/crumbIssuer/api/json/"
CheckScriptCompileUrl = "/job/init-job/descriptorByName/org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition/checkScriptCompile" CheckScriptCompileUrl = "/job/init-job/descriptorByName/org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition/checkScriptCompile"
CheckCronUrl = "/job/init-job/descriptorByName/hudson.triggers.TimerTrigger/checkSpec?" 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" ToJenkinsfileUrl = "/pipeline-model-converter/toJenkinsfile"
ToJsonUrl = "/pipeline-model-converter/toJson" ToJsonUrl = "/pipeline-model-converter/toJson"
GetNotifyCommitUrl = "/git/notifyCommit/?" GetNotifyCommitUrl = "/git/notifyCommit/?"
......
...@@ -21,7 +21,7 @@ import ( ...@@ -21,7 +21,7 @@ import (
) )
var ( var (
jenkinsClientOnce sync.Once jenkinsInitMutex sync.Mutex
jenkinsClient *gojenkins.Jenkins jenkinsClient *gojenkins.Jenkins
jenkinsAdminAddress string jenkinsAdminAddress string
jenkinsAdminUsername string jenkinsAdminUsername string
...@@ -41,35 +41,36 @@ func init() { ...@@ -41,35 +41,36 @@ func init() {
} }
func Client() *gojenkins.Jenkins { func Client() *gojenkins.Jenkins {
jenkinsClientOnce.Do(func() { if jenkinsClient == nil {
jenkins := gojenkins.CreateJenkins(nil, jenkinsAdminAddress, jenkinsMaxConn, jenkinsAdminUsername, jenkinsAdminPassword) jenkinsInitMutex.Lock()
jenkins, err := jenkins.Init() defer jenkinsInitMutex.Unlock()
if err != nil { if jenkinsClient == nil {
glog.Error("failed to connect jenkins") jenkins := gojenkins.CreateJenkins(nil, jenkinsAdminAddress, jenkinsMaxConn, jenkinsAdminUsername, jenkinsAdminPassword)
return jenkins, err := jenkins.Init()
} if err != nil {
jenkinsClient = jenkins glog.Errorf("failed to connect jenkins, %+v", err)
globalRole, err := jenkins.GetGlobalRole(JenkinsAllUserRoleName) }
if err != nil { globalRole, err := jenkins.GetGlobalRole(JenkinsAllUserRoleName)
glog.Error("failed to get jenkins role") if err != nil {
} glog.Errorf("failed to get jenkins role, %+v", err)
if globalRole == nil { }
_, err := jenkins.AddGlobalRole(JenkinsAllUserRoleName, gojenkins.GlobalPermissionIds{ if globalRole == nil {
GlobalRead: true, _, err := jenkins.AddGlobalRole(JenkinsAllUserRoleName, gojenkins.GlobalPermissionIds{
GlobalRead: true,
}, true)
if err != nil {
glog.Errorf("failed to create jenkins global role, %+v", err)
}
}
_, err = jenkins.AddProjectRole(JenkinsAllUserRoleName, "\\n\\s*\\r", gojenkins.ProjectPermissionIds{
SCMTag: true,
}, true) }, true)
if err != nil { if err != nil {
glog.Error("failed to create jenkins global role") glog.Errorf("failed to create jenkins project role, %+v", err)
return
} }
jenkinsClient = jenkins
} }
_, err = jenkins.AddProjectRole(JenkinsAllUserRoleName, "\\n\\s*\\r", gojenkins.ProjectPermissionIds{ }
SCMTag: true,
}, true)
if err != nil {
glog.Error("failed to create jenkins project role")
return
}
})
return jenkinsClient return jenkinsClient
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册