@@ -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)
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user