Merge branch 'master' into jenkins-pageable-response
Signed-off-by: runzexia <runzexia@yunify.com> # Conflicts: # pkg/models/devops/devops.go
This commit is contained in:
@@ -23,13 +23,14 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
log "github.com/golang/glog"
|
||||
"github.com/emicklei/go-restful"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/gojenkins"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/admin_jenkins"
|
||||
|
||||
log "k8s.io/klog"
|
||||
cs "kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
@@ -37,17 +38,18 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const channelMaxCapacity = 100
|
||||
|
||||
var jenkins *gojenkins.Jenkins
|
||||
|
||||
func JenkinsInit() {
|
||||
jenkins = admin_jenkins.GetJenkins()
|
||||
}
|
||||
const (
|
||||
channelMaxCapacity = 100
|
||||
cronJobLayout = "Monday, January 2, 2006 15:04:05 PM"
|
||||
)
|
||||
|
||||
func GetPipeline(projectName, pipelineName string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetPipelineUrl, projectName, pipelineName)
|
||||
log.Infof("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetPipelineUrl, projectName, pipelineName)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -59,8 +61,12 @@ func GetPipeline(projectName, pipelineName string, req *http.Request) ([]byte, e
|
||||
}
|
||||
|
||||
func SearchPipelines(req *http.Request) ([]byte, error) {
|
||||
baseUrl := jenkins.Server + SearchPipelineUrl + req.URL.RawQuery
|
||||
klog.V(3).Infof("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := devops.Jenkins().Server + SearchPipelineUrl + req.URL.RawQuery
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -87,13 +93,18 @@ func SearchPipelines(req *http.Request) ([]byte, error) {
|
||||
}
|
||||
|
||||
func searchPipelineCount(req *http.Request) (int, error) {
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return 0, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
query, _ := parseJenkinsQuery(req.URL.RawQuery)
|
||||
query.Set("start", "0")
|
||||
query.Set("limit", "1000")
|
||||
query.Set("depth", "-1")
|
||||
|
||||
baseUrl := jenkins.Server + SearchPipelineUrl + query.Encode()
|
||||
klog.Infof("Jenkins-url: " + baseUrl)
|
||||
baseUrl := devops.Jenkins().Server + SearchPipelineUrl + query.Encode()
|
||||
klog.V(4).Info("Jenkins-url: " + baseUrl)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -110,13 +121,17 @@ func searchPipelineCount(req *http.Request) (int, error) {
|
||||
}
|
||||
|
||||
func searchPipelineRunsCount(projectName, pipelineName string, req *http.Request) (int, error) {
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return 0, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
query, _ := parseJenkinsQuery(req.URL.RawQuery)
|
||||
query.Set("start", "0")
|
||||
query.Set("limit", "1000")
|
||||
query.Set("depth", "-1")
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+SearchPipelineRunUrl, projectName, pipelineName)
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+SearchPipelineRunUrl, projectName, pipelineName)
|
||||
|
||||
klog.V(3).Info("Jenkins-url: " + baseUrl)
|
||||
klog.V(4).Info("Jenkins-url: " + baseUrl)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl+query.Encode(), req)
|
||||
if err != nil {
|
||||
@@ -133,9 +148,14 @@ func searchPipelineRunsCount(projectName, pipelineName string, req *http.Request
|
||||
}
|
||||
|
||||
func SearchPipelineRuns(projectName, pipelineName string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+SearchPipelineRunUrl, projectName, pipelineName)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
klog.V(3).Info("Jenkins-url: " + baseUrl)
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+SearchPipelineRunUrl, projectName, pipelineName)
|
||||
|
||||
klog.V(4).Info("Jenkins-url: " + baseUrl)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl+req.URL.RawQuery, req)
|
||||
if err != nil {
|
||||
@@ -162,8 +182,12 @@ func SearchPipelineRuns(projectName, pipelineName string, req *http.Request) ([]
|
||||
}
|
||||
|
||||
func GetBranchPipelineRun(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetPipeBranchRunUrl, projectName, pipelineName, branchName, runId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetPipeBranchRunUrl, projectName, pipelineName, branchName, runId)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -175,7 +199,12 @@ func GetBranchPipelineRun(projectName, pipelineName, branchName, runId string, r
|
||||
}
|
||||
|
||||
func GetPipelineRunNodesbyBranch(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetBranchPipeRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetBranchPipeRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
@@ -188,8 +217,12 @@ func GetPipelineRunNodesbyBranch(projectName, pipelineName, branchName, runId st
|
||||
}
|
||||
|
||||
func GetBranchStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId string, req *http.Request) ([]byte, http.Header, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetBranchStepLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetBranchStepLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId)
|
||||
|
||||
resBody, header, err := jenkinsClient(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -201,8 +234,12 @@ func GetBranchStepLog(projectName, pipelineName, branchName, runId, nodeId, step
|
||||
}
|
||||
|
||||
func GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, req *http.Request) ([]byte, http.Header, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetStepLogUrl+req.URL.RawQuery, projectName, pipelineName, runId, nodeId, stepId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetStepLogUrl+req.URL.RawQuery, projectName, pipelineName, runId, nodeId, stepId)
|
||||
|
||||
resBody, header, err := jenkinsClient(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -211,12 +248,15 @@ func GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, req *ht
|
||||
}
|
||||
|
||||
return resBody, header, err
|
||||
|
||||
}
|
||||
|
||||
func GetSCMServers(scmId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetSCMServersUrl, scmId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetSCMServersUrl, scmId)
|
||||
req.Method = http.MethodGet
|
||||
resBody, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -227,6 +267,11 @@ func GetSCMServers(scmId string, req *http.Request) ([]byte, error) {
|
||||
}
|
||||
|
||||
func CreateSCMServers(scmId string, req *http.Request) ([]byte, error) {
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
requestBody, err := ioutil.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
@@ -244,6 +289,7 @@ func CreateSCMServers(scmId string, req *http.Request) ([]byte, error) {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var servers []*SCMServer
|
||||
_ = json.Unmarshal(byteServers, &servers)
|
||||
for _, server := range servers {
|
||||
@@ -252,8 +298,9 @@ func CreateSCMServers(scmId string, req *http.Request) ([]byte, error) {
|
||||
}
|
||||
}
|
||||
req.Body = ioutil.NopCloser(bytes.NewReader(requestBody))
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+CreateSCMServersUrl, scmId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+CreateSCMServersUrl, scmId)
|
||||
|
||||
req.Method = http.MethodPost
|
||||
resBody, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -264,8 +311,12 @@ func CreateSCMServers(scmId string, req *http.Request) ([]byte, error) {
|
||||
}
|
||||
|
||||
func Validate(scmId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+ValidateUrl, scmId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+ValidateUrl, scmId)
|
||||
|
||||
req.Method = http.MethodPut
|
||||
resBody, err := sendJenkinsRequest(baseUrl, req)
|
||||
@@ -278,8 +329,12 @@ func Validate(scmId string, req *http.Request) ([]byte, error) {
|
||||
}
|
||||
|
||||
func GetSCMOrg(scmId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetSCMOrgUrl+req.URL.RawQuery, scmId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetSCMOrgUrl+req.URL.RawQuery, scmId)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -291,8 +346,12 @@ func GetSCMOrg(scmId string, req *http.Request) ([]byte, error) {
|
||||
}
|
||||
|
||||
func GetOrgRepo(scmId, organizationId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetOrgRepoUrl+req.URL.RawQuery, scmId, organizationId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetOrgRepoUrl+req.URL.RawQuery, scmId, organizationId)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -304,8 +363,12 @@ func GetOrgRepo(scmId, organizationId string, req *http.Request) ([]byte, error)
|
||||
}
|
||||
|
||||
func StopBranchPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+StopBranchPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+StopBranchPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
|
||||
|
||||
req.Method = http.MethodPut
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
@@ -318,8 +381,12 @@ func StopBranchPipeline(projectName, pipelineName, branchName, runId string, req
|
||||
}
|
||||
|
||||
func StopPipeline(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+StopPipelineUrl+req.URL.RawQuery, projectName, pipelineName, runId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+StopPipelineUrl+req.URL.RawQuery, projectName, pipelineName, runId)
|
||||
|
||||
req.Method = http.MethodPut
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
@@ -332,8 +399,12 @@ func StopPipeline(projectName, pipelineName, runId string, req *http.Request) ([
|
||||
}
|
||||
|
||||
func ReplayBranchPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+ReplayBranchPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+ReplayBranchPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -345,8 +416,12 @@ func ReplayBranchPipeline(projectName, pipelineName, branchName, runId string, r
|
||||
}
|
||||
|
||||
func ReplayPipeline(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+ReplayPipelineUrl+req.URL.RawQuery, projectName, pipelineName, runId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+ReplayPipelineUrl+req.URL.RawQuery, projectName, pipelineName, runId)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -358,8 +433,12 @@ func ReplayPipeline(projectName, pipelineName, runId string, req *http.Request)
|
||||
}
|
||||
|
||||
func GetBranchRunLog(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetBranchRunLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetBranchRunLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -371,8 +450,12 @@ func GetBranchRunLog(projectName, pipelineName, branchName, runId string, req *h
|
||||
}
|
||||
|
||||
func GetRunLog(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetRunLogUrl+req.URL.RawQuery, projectName, pipelineName, runId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetRunLogUrl+req.URL.RawQuery, projectName, pipelineName, runId)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -384,8 +467,12 @@ func GetRunLog(projectName, pipelineName, runId string, req *http.Request) ([]by
|
||||
}
|
||||
|
||||
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.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetBranchArtifactsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -397,8 +484,12 @@ func GetBranchArtifacts(projectName, pipelineName, branchName, runId string, req
|
||||
}
|
||||
|
||||
func GetArtifacts(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetArtifactsUrl+req.URL.RawQuery, projectName, pipelineName, runId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetArtifactsUrl+req.URL.RawQuery, projectName, pipelineName, runId)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -410,8 +501,12 @@ func GetArtifacts(projectName, pipelineName, runId string, req *http.Request) ([
|
||||
}
|
||||
|
||||
func GetPipeBranch(projectName, pipelineName string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetPipeBranchUrl, projectName, pipelineName)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetPipeBranchUrl, projectName, pipelineName)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl+req.URL.RawQuery, req)
|
||||
if err != nil {
|
||||
@@ -423,8 +518,12 @@ func GetPipeBranch(projectName, pipelineName string, req *http.Request) ([]byte,
|
||||
}
|
||||
|
||||
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)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+CheckBranchPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId)
|
||||
|
||||
newBody, err := getInputReqBody(req.Body)
|
||||
if err != nil {
|
||||
@@ -442,8 +541,12 @@ func SubmitBranchInputStep(projectName, pipelineName, branchName, runId, nodeId,
|
||||
}
|
||||
|
||||
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)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+CheckPipelineUrl+req.URL.RawQuery, projectName, pipelineName, runId, nodeId, stepId)
|
||||
|
||||
newBody, err := getInputReqBody(req.Body)
|
||||
if err != nil {
|
||||
@@ -500,8 +603,12 @@ func parseBody(body io.Reader) (newReqBody io.ReadCloser) {
|
||||
}
|
||||
|
||||
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)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetConsoleLogUrl+req.URL.RawQuery, projectName, pipelineName)
|
||||
|
||||
resBody, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -513,8 +620,12 @@ func GetConsoleLog(projectName, pipelineName string, req *http.Request) ([]byte,
|
||||
}
|
||||
|
||||
func ScanBranch(projectName, pipelineName string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+ScanBranchUrl+req.URL.RawQuery, projectName, pipelineName)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+ScanBranchUrl+req.URL.RawQuery, projectName, pipelineName)
|
||||
|
||||
resBody, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -526,8 +637,12 @@ func ScanBranch(projectName, pipelineName string, req *http.Request) ([]byte, er
|
||||
}
|
||||
|
||||
func RunBranchPipeline(projectName, pipelineName, branchName string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+RunBranchPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+RunBranchPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -539,8 +654,11 @@ func RunBranchPipeline(projectName, pipelineName, branchName string, req *http.R
|
||||
}
|
||||
|
||||
func RunPipeline(projectName, pipelineName string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+RunPipelineUrl+req.URL.RawQuery, projectName, pipelineName)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+RunPipelineUrl+req.URL.RawQuery, projectName, pipelineName)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -552,8 +670,12 @@ func RunPipeline(projectName, pipelineName string, req *http.Request) ([]byte, e
|
||||
}
|
||||
|
||||
func GetCrumb(req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server + GetCrumbUrl)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server + GetCrumbUrl)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -564,10 +686,13 @@ func GetCrumb(req *http.Request) ([]byte, error) {
|
||||
return res, err
|
||||
}
|
||||
|
||||
func CheckScriptCompile(req *http.Request) ([]byte, error) {
|
||||
baseUrl := jenkins.Server + CheckScriptCompileUrl
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
req.SetBasicAuth(jenkins.Requester.BasicAuth.Username, jenkins.Requester.BasicAuth.Password)
|
||||
func CheckScriptCompile(projectName, pipelineName string, req *http.Request) ([]byte, error) {
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+CheckScriptCompileUrl, projectName, pipelineName)
|
||||
|
||||
resBody, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -578,41 +703,111 @@ func CheckScriptCompile(req *http.Request) ([]byte, error) {
|
||||
return resBody, err
|
||||
}
|
||||
|
||||
func CheckCron(req *http.Request) (*CheckCronRes, error) {
|
||||
newurl, err := url.Parse(jenkins.Server + CheckCronUrl + req.URL.RawQuery)
|
||||
func CheckCron(projectName string, req *http.Request) (*CheckCronRes, error) {
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
jenkins := devops.Jenkins()
|
||||
|
||||
var res = new(CheckCronRes)
|
||||
var cron = new(CronData)
|
||||
var reader io.ReadCloser
|
||||
var baseUrl string
|
||||
|
||||
reader = req.Body
|
||||
cronData, err := ioutil.ReadAll(reader)
|
||||
json.Unmarshal(cronData, cron)
|
||||
|
||||
if cron.PipelineName != "" {
|
||||
baseUrl = fmt.Sprintf(jenkins.Server+CheckPipelienCronUrl, projectName, cron.PipelineName, cron.Cron)
|
||||
} else {
|
||||
baseUrl = fmt.Sprintf(jenkins.Server+CheckCronUrl, projectName, cron.Cron)
|
||||
}
|
||||
|
||||
newUrl, err := url.Parse(baseUrl)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
newUrl.RawQuery = newUrl.Query().Encode()
|
||||
|
||||
reqJenkins := &http.Request{
|
||||
Method: http.MethodGet,
|
||||
URL: newurl,
|
||||
Header: http.Header{},
|
||||
URL: newUrl,
|
||||
Header: req.Header,
|
||||
}
|
||||
var res = new(CheckCronRes)
|
||||
|
||||
client := &http.Client{Timeout: 30 * time.Second}
|
||||
|
||||
reqJenkins.SetBasicAuth(jenkins.Requester.BasicAuth.Username, jenkins.Requester.BasicAuth.Password)
|
||||
|
||||
resp, err := client.Do(reqJenkins)
|
||||
|
||||
if resp != nil && resp.StatusCode != http.StatusOK {
|
||||
resBody, _ := getRespBody(resp)
|
||||
return &CheckCronRes{
|
||||
Result: "error",
|
||||
Message: string(resBody),
|
||||
}, err
|
||||
}
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return res, err
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(resp.Body)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return res, err
|
||||
return nil, err
|
||||
}
|
||||
doc.Find("div").Each(func(i int, selection *goquery.Selection) {
|
||||
res.Message = selection.Text()
|
||||
res.Result, _ = selection.Attr("class")
|
||||
})
|
||||
if res.Result == "ok" {
|
||||
res.LastTime, res.NextTime, err = parseCronJobTime(res.Message)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
func parseCronJobTime(msg string) (string, string, error) {
|
||||
|
||||
times := strings.Split(msg, ";")
|
||||
|
||||
lastTmp := strings.SplitN(times[0], " ", 2)
|
||||
lastTime := strings.SplitN(lastTmp[1], " UTC", 2)
|
||||
lastUinx, err := time.Parse(cronJobLayout, lastTime[0])
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return "", "", err
|
||||
}
|
||||
last := lastUinx.Format(time.RFC3339)
|
||||
|
||||
nextTmp := strings.SplitN(times[1], " ", 3)
|
||||
nextTime := strings.SplitN(nextTmp[2], " UTC", 2)
|
||||
nextUinx, err := time.Parse(cronJobLayout, nextTime[0])
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return "", "", err
|
||||
}
|
||||
next := nextUinx.Format(time.RFC3339)
|
||||
|
||||
return last, next, nil
|
||||
}
|
||||
|
||||
func GetPipelineRun(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetPipelineRunUrl, projectName, pipelineName, runId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetPipelineRunUrl, projectName, pipelineName, runId)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -624,8 +819,12 @@ func GetPipelineRun(projectName, pipelineName, runId string, req *http.Request)
|
||||
}
|
||||
|
||||
func GetBranchPipeline(projectName, pipelineName, branchName string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetBranchPipeUrl, projectName, pipelineName, branchName)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetBranchPipeUrl, projectName, pipelineName, branchName)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -637,8 +836,12 @@ func GetBranchPipeline(projectName, pipelineName, branchName string, req *http.R
|
||||
}
|
||||
|
||||
func GetPipelineRunNodes(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetPipeRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, runId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetPipeRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, runId)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -650,8 +853,12 @@ func GetPipelineRunNodes(projectName, pipelineName, runId string, req *http.Requ
|
||||
}
|
||||
|
||||
func GetBranchNodeSteps(projectName, pipelineName, branchName, runId, nodeId string, req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server+GetBranchNodeStepsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetBranchNodeStepsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -663,8 +870,12 @@ func GetBranchNodeSteps(projectName, pipelineName, branchName, runId, nodeId str
|
||||
}
|
||||
|
||||
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.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server+GetNodeStepsUrl+req.URL.RawQuery, projectName, pipelineName, runId, nodeId)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -676,8 +887,12 @@ func GetNodeSteps(projectName, pipelineName, runId, nodeId string, req *http.Req
|
||||
}
|
||||
|
||||
func ToJenkinsfile(req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server + ToJenkinsfileUrl)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server + ToJenkinsfileUrl)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -689,8 +904,12 @@ func ToJenkinsfile(req *http.Request) ([]byte, error) {
|
||||
}
|
||||
|
||||
func ToJson(req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprintf(jenkins.Server + ToJsonUrl)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf(devops.Jenkins().Server + ToJsonUrl)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -702,8 +921,12 @@ func ToJson(req *http.Request) ([]byte, error) {
|
||||
}
|
||||
|
||||
func GetNotifyCommit(req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprint(jenkins.Server, GetNotifyCommitUrl, req.URL.RawQuery)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprint(devops.Jenkins().Server, GetNotifyCommitUrl, req.URL.RawQuery)
|
||||
req.Method = "GET"
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
@@ -716,8 +939,12 @@ func GetNotifyCommit(req *http.Request) ([]byte, error) {
|
||||
}
|
||||
|
||||
func GithubWebhook(req *http.Request) ([]byte, error) {
|
||||
baseUrl := fmt.Sprint(jenkins.Server, GithubWebhookUrl, req.URL.RawQuery)
|
||||
log.Info("Jenkins-url: " + baseUrl)
|
||||
devops, err := cs.ClientSets().Devops()
|
||||
if err != nil {
|
||||
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprint(devops.Jenkins().Server, GithubWebhookUrl, req.URL.RawQuery)
|
||||
|
||||
res, err := sendJenkinsRequest(baseUrl, req)
|
||||
if err != nil {
|
||||
@@ -729,8 +956,6 @@ func GithubWebhook(req *http.Request) ([]byte, error) {
|
||||
}
|
||||
|
||||
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.Info("getNodesUrl: " + getNodesUrl)
|
||||
var wg sync.WaitGroup
|
||||
var nodesDetails []NodesDetail
|
||||
stepChan := make(chan *NodesStepsIndex, channelMaxCapacity)
|
||||
@@ -776,8 +1001,6 @@ func GetBranchNodesDetail(projectName, pipelineName, branchName, runId string, r
|
||||
}
|
||||
|
||||
func GetNodesDetail(projectName, pipelineName, runId string, req *http.Request) ([]NodesDetail, error) {
|
||||
getNodesUrl := fmt.Sprintf(jenkins.Server+GetPipeRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, runId)
|
||||
log.Info("getNodesUrl: " + getNodesUrl)
|
||||
var wg sync.WaitGroup
|
||||
var nodesDetails []NodesDetail
|
||||
stepChan := make(chan *NodesStepsIndex, channelMaxCapacity)
|
||||
|
||||
Reference in New Issue
Block a user