未验证 提交 dde017c4 编写于 作者: S soulseen

fix checkpipeline

Signed-off-by: Nsoulseen <sunzhu@yunify.com>
上级 d30dba89
...@@ -516,7 +516,7 @@ The last one is encrypted info, such as the password of the username-password ty ...@@ -516,7 +516,7 @@ The last one is encrypted info, such as the password of the username-password ty
// /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps/{step} // /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps/{step}
webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps/{step}"). webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps/{step}").
To(devopsapi.CheckBranchPipeline). To(devopsapi.SubmitBranchInputStep).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}). Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
Doc("(MultiBranchesPipeline) Proceed or Break the paused pipeline which waiting for user input."). Doc("(MultiBranchesPipeline) Proceed or Break the paused pipeline which waiting for user input.").
Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")). Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
...@@ -530,7 +530,7 @@ The last one is encrypted info, such as the password of the username-password ty ...@@ -530,7 +530,7 @@ The last one is encrypted info, such as the password of the username-password ty
// match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/runs/{run}/nodes/{node}/steps/{step} // match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/runs/{run}/nodes/{node}/steps/{step}
webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/runs/{run}/nodes/{node}/steps/{step}"). webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/runs/{run}/nodes/{node}/steps/{step}").
To(devopsapi.CheckPipeline). To(devopsapi.SubmitInputStep).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}). Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
Doc("Proceed or Break the paused pipeline which waiting for user input."). Doc("Proceed or Break the paused pipeline which waiting for user input.").
Reads(devops.CheckPlayload{}). Reads(devops.CheckPlayload{}).
......
...@@ -314,7 +314,7 @@ func GetPipeBranch(req *restful.Request, resp *restful.Response) { ...@@ -314,7 +314,7 @@ func GetPipeBranch(req *restful.Request, resp *restful.Response) {
resp.Write(res) resp.Write(res)
} }
func CheckBranchPipeline(req *restful.Request, resp *restful.Response) { func SubmitBranchInputStep(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("devops") projectName := req.PathParameter("devops")
pipelineName := req.PathParameter("pipeline") pipelineName := req.PathParameter("pipeline")
branchName := req.PathParameter("branch") branchName := req.PathParameter("branch")
...@@ -322,7 +322,7 @@ func CheckBranchPipeline(req *restful.Request, resp *restful.Response) { ...@@ -322,7 +322,7 @@ func CheckBranchPipeline(req *restful.Request, resp *restful.Response) {
nodeId := req.PathParameter("node") nodeId := req.PathParameter("node")
stepId := req.PathParameter("step") stepId := req.PathParameter("step")
res, err := devops.CheckBranchPipeline(projectName, pipelineName, branchName, runId, nodeId, stepId, req.Request) res, err := devops.SubmitBranchInputStep(projectName, pipelineName, branchName, runId, nodeId, stepId, req.Request)
if err != nil { if err != nil {
parseErr(err, resp) parseErr(err, resp)
return return
...@@ -331,14 +331,14 @@ func CheckBranchPipeline(req *restful.Request, resp *restful.Response) { ...@@ -331,14 +331,14 @@ func CheckBranchPipeline(req *restful.Request, resp *restful.Response) {
resp.Write(res) resp.Write(res)
} }
func CheckPipeline(req *restful.Request, resp *restful.Response) { func SubmitInputStep(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("devops") projectName := req.PathParameter("devops")
pipelineName := req.PathParameter("pipeline") pipelineName := req.PathParameter("pipeline")
runId := req.PathParameter("run") runId := req.PathParameter("run")
nodeId := req.PathParameter("node") nodeId := req.PathParameter("node")
stepId := req.PathParameter("step") stepId := req.PathParameter("step")
res, err := devops.CheckPipeline(projectName, pipelineName, runId, nodeId, stepId, req.Request) res, err := devops.SubmitInputStep(projectName, pipelineName, runId, nodeId, stepId, req.Request)
if err != nil { if err != nil {
parseErr(err, resp) parseErr(err, resp)
return return
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package devops package devops
import ( import (
"bytes"
"compress/gzip" "compress/gzip"
"encoding/json" "encoding/json"
"fmt" "fmt"
...@@ -293,10 +294,16 @@ func GetPipeBranch(projectName, pipelineName string, req *http.Request) ([]byte, ...@@ -293,10 +294,16 @@ func GetPipeBranch(projectName, pipelineName string, req *http.Request) ([]byte,
return res, err return res, err
} }
func CheckBranchPipeline(projectName, pipelineName, branchName, runId, nodeId, stepId string, req *http.Request) ([]byte, error) { func SubmitBranchInputStep(projectName, pipelineName, branchName, runId, nodeId, stepId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+CheckBranchPipelineUrl+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.Info("Jenkins-url: " + baseUrl) log.Info("Jenkins-url: " + baseUrl)
newBody, err := getInputReqBody(req.Body)
if err != nil {
log.Error(err)
return nil, err
}
req.Body = newBody
resBody, err := sendJenkinsRequest(baseUrl, req) resBody, err := sendJenkinsRequest(baseUrl, req)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
...@@ -306,10 +313,16 @@ func CheckBranchPipeline(projectName, pipelineName, branchName, runId, nodeId, s ...@@ -306,10 +313,16 @@ func CheckBranchPipeline(projectName, pipelineName, branchName, runId, nodeId, s
return resBody, err return resBody, err
} }
func CheckPipeline(projectName, pipelineName, runId, nodeId, stepId string, req *http.Request) ([]byte, error) { func SubmitInputStep(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) baseUrl := fmt.Sprintf(jenkins.Server+CheckPipelineUrl+req.URL.RawQuery, projectName, pipelineName, runId, nodeId, stepId)
log.Info("Jenkins-url: " + baseUrl) log.Info("Jenkins-url: " + baseUrl)
newBody, err := getInputReqBody(req.Body)
if err != nil {
log.Error(err)
return nil, err
}
req.Body = newBody
resBody, err := sendJenkinsRequest(baseUrl, req) resBody, err := sendJenkinsRequest(baseUrl, req)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
...@@ -319,6 +332,45 @@ func CheckPipeline(projectName, pipelineName, runId, nodeId, stepId string, req ...@@ -319,6 +332,45 @@ func CheckPipeline(projectName, pipelineName, runId, nodeId, stepId string, req
return resBody, err return resBody, err
} }
func getInputReqBody(reqBody io.ReadCloser) (newReqBody io.ReadCloser, err error) {
var checkBody CheckPlayload
var jsonBody []byte
var workRound struct {
ID string `json:"id,omitempty" description:"id"`
Parameters []CheckPlayloadParameters `json:"parameters"`
Abort bool `json:"abort,omitempty" description:"abort or not"`
}
Body, err := ioutil.ReadAll(reqBody)
if err != nil {
log.Error(err)
return nil, err
}
err = json.Unmarshal(Body, &checkBody)
if checkBody.Abort != true && checkBody.Parameters == nil {
workRound.Parameters = []CheckPlayloadParameters{}
workRound.ID = checkBody.ID
jsonBody, _ = json.Marshal(workRound)
} else {
jsonBody, _ = json.Marshal(checkBody)
}
newReqBody = parseBody(bytes.NewBuffer(jsonBody))
return newReqBody, nil
}
func parseBody(body io.Reader) (newReqBody io.ReadCloser) {
rc, ok := body.(io.ReadCloser)
if !ok && body != nil {
rc = ioutil.NopCloser(body)
}
return rc
}
func GetConsoleLog(projectName, pipelineName string, req *http.Request) ([]byte, error) { func GetConsoleLog(projectName, pipelineName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+GetConsoleLogUrl+req.URL.RawQuery, projectName, pipelineName) baseUrl := fmt.Sprintf(jenkins.Server+GetConsoleLogUrl+req.URL.RawQuery, projectName, pipelineName)
log.Info("Jenkins-url: " + baseUrl) log.Info("Jenkins-url: " + baseUrl)
......
...@@ -717,11 +717,13 @@ type NodeStatus struct { ...@@ -717,11 +717,13 @@ type NodeStatus struct {
// CheckPipeline // CheckPipeline
type CheckPlayload struct { type CheckPlayload struct {
ID string `json:"id,omitempty" description:"id"` ID string `json:"id,omitempty" description:"id"`
Parameters []struct { Parameters []CheckPlayloadParameters `json:"parameters,omitempty"`
Abort bool `json:"abort,omitempty" description:"abort or not"`
}
type CheckPlayloadParameters struct {
Name string `json:"name,omitempty" description:"name"` Name string `json:"name,omitempty" description:"name"`
Value string `json:"value,omitempty" description:"value"` Value string `json:"value,omitempty" description:"value"`
} `json:"parameters,omitempty"`
Abort bool `json:"abort,omitempty" description:"abort or not"`
} }
// Getcrumb // Getcrumb
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册