@@ -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}
|
||||
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}).
|
||||
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")).
|
||||
@@ -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}
|
||||
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}).
|
||||
Doc("Proceed or Break the paused pipeline which waiting for user input.").
|
||||
Reads(devops.CheckPlayload{}).
|
||||
|
||||
@@ -314,7 +314,7 @@ func GetPipeBranch(req *restful.Request, resp *restful.Response) {
|
||||
resp.Write(res)
|
||||
}
|
||||
|
||||
func CheckBranchPipeline(req *restful.Request, resp *restful.Response) {
|
||||
func SubmitBranchInputStep(req *restful.Request, resp *restful.Response) {
|
||||
projectName := req.PathParameter("devops")
|
||||
pipelineName := req.PathParameter("pipeline")
|
||||
branchName := req.PathParameter("branch")
|
||||
@@ -322,7 +322,7 @@ func CheckBranchPipeline(req *restful.Request, resp *restful.Response) {
|
||||
nodeId := req.PathParameter("node")
|
||||
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 {
|
||||
parseErr(err, resp)
|
||||
return
|
||||
@@ -331,14 +331,14 @@ func CheckBranchPipeline(req *restful.Request, resp *restful.Response) {
|
||||
resp.Write(res)
|
||||
}
|
||||
|
||||
func CheckPipeline(req *restful.Request, resp *restful.Response) {
|
||||
func SubmitInputStep(req *restful.Request, resp *restful.Response) {
|
||||
projectName := req.PathParameter("devops")
|
||||
pipelineName := req.PathParameter("pipeline")
|
||||
runId := req.PathParameter("run")
|
||||
nodeId := req.PathParameter("node")
|
||||
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 {
|
||||
parseErr(err, resp)
|
||||
return
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package devops
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -293,10 +294,16 @@ func GetPipeBranch(projectName, pipelineName string, req *http.Request) ([]byte,
|
||||
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)
|
||||
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)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
@@ -306,10 +313,16 @@ func CheckBranchPipeline(projectName, pipelineName, branchName, runId, nodeId, s
|
||||
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)
|
||||
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)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
@@ -319,6 +332,45 @@ func CheckPipeline(projectName, pipelineName, runId, nodeId, stepId string, req
|
||||
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) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetConsoleLogUrl+req.URL.RawQuery, projectName, pipelineName)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
|
||||
@@ -716,12 +716,14 @@ type NodeStatus struct {
|
||||
|
||||
// CheckPipeline
|
||||
type CheckPlayload struct {
|
||||
ID string `json:"id,omitempty" description:"id"`
|
||||
Parameters []struct {
|
||||
Name string `json:"name,omitempty" description:"name"`
|
||||
Value string `json:"value,omitempty" description:"value"`
|
||||
} `json:"parameters,omitempty"`
|
||||
Abort bool `json:"abort,omitempty" description:"abort or not"`
|
||||
ID string `json:"id,omitempty" description:"id"`
|
||||
Parameters []CheckPlayloadParameters `json:"parameters,omitempty"`
|
||||
Abort bool `json:"abort,omitempty" description:"abort or not"`
|
||||
}
|
||||
|
||||
type CheckPlayloadParameters struct {
|
||||
Name string `json:"name,omitempty" description:"name"`
|
||||
Value string `json:"value,omitempty" description:"value"`
|
||||
}
|
||||
|
||||
// Getcrumb
|
||||
|
||||
Reference in New Issue
Block a user