add jenkins pre-check & fix jenkins flag
Signed-off-by: soulseen <sunzhu@yunify.com>
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/servicemesh/tracing"
|
||||
"kubesphere.io/kubesphere/pkg/filter"
|
||||
"kubesphere.io/kubesphere/pkg/informers"
|
||||
"kubesphere.io/kubesphere/pkg/models/devops"
|
||||
logging "kubesphere.io/kubesphere/pkg/models/log"
|
||||
"kubesphere.io/kubesphere/pkg/signals"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/admin_jenkins"
|
||||
@@ -98,6 +99,7 @@ func Run(s *options.ServerRunOptions) error {
|
||||
}
|
||||
|
||||
func initializeAdminJenkins() {
|
||||
devops.PreCheckJenkins()
|
||||
admin_jenkins.Client()
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ func GetPipeline(req *restful.Request, resp *restful.Response) {
|
||||
return
|
||||
}
|
||||
|
||||
resp.Header().Set(restful.HEADER_ContentType, "application/json")
|
||||
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
|
||||
resp.Write(res)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,27 +19,47 @@ package devops
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/emicklei/go-restful"
|
||||
log "github.com/golang/glog"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/admin_jenkins"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const MIME_FORM = "application/x-www-form-urlencoded"
|
||||
|
||||
var (
|
||||
jenkinsUrl string
|
||||
jenkinsAdminUsername string
|
||||
jenkinsAdminPassword string
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&jenkinsUrl, "jenkins-url", "http://ks-jenkins.kubesphere-devops-system.svc.cluster.local:80", "jenkins server host")
|
||||
flag.StringVar(&jenkinsAdminUsername, "jenkins-adminusername", "admin", "admin username of jenkins")
|
||||
flag.StringVar(&jenkinsAdminPassword, "jenkins-adminpassword", "passw0rd", "admin password of jenkins")
|
||||
func PreCheckJenkins() {
|
||||
jenkinsUrl, jenkinsAdminUsername, jenkinsAdminPassword = admin_jenkins.GetJenkinsFlag()
|
||||
baseUrl := jenkinsUrl + LoginUrl
|
||||
|
||||
client := &http.Client{Timeout: 30 * time.Second}
|
||||
|
||||
loginReq, _ := http.NewRequest(http.MethodPost, baseUrl, strings.NewReader(""))
|
||||
loginReq.Header.Add(restful.HEADER_ContentType, MIME_FORM)
|
||||
loginReq.SetBasicAuth(jenkinsAdminUsername, jenkinsAdminPassword)
|
||||
|
||||
resp, err := client.Do(loginReq)
|
||||
|
||||
if err != nil {
|
||||
log.Error("Check Jenkins Error: ", err)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
log.Error("Check Jenkins Error: ", resp.StatusCode, http.StatusText(resp.StatusCode))
|
||||
} else {
|
||||
log.Infof("Client Jenkins Success: " + baseUrl)
|
||||
}
|
||||
}
|
||||
|
||||
func GetPipeline(projectName, pipelineName string, req *http.Request) ([]byte, error) {
|
||||
|
||||
@@ -49,4 +49,5 @@ const (
|
||||
ToJsonUrl = "/pipeline-model-converter/toJson"
|
||||
GetNotifyCommitUrl = "/git/notifyCommit/?"
|
||||
GithubWebhookUrl = "/github-webhook/"
|
||||
LoginUrl = "/j_acegi_security_check"
|
||||
)
|
||||
|
||||
@@ -40,6 +40,10 @@ func init() {
|
||||
flag.IntVar(&jenkinsMaxConn, "jenkins-max-conn", 20, "max conn to jenkins")
|
||||
}
|
||||
|
||||
func GetJenkinsFlag() (string,string,string){
|
||||
return jenkinsAdminAddress, jenkinsAdminUsername, jenkinsAdminPassword
|
||||
}
|
||||
|
||||
func Client() *gojenkins.Jenkins {
|
||||
jenkinsClientOnce.Do(func() {
|
||||
jenkins := gojenkins.CreateJenkins(nil, jenkinsAdminAddress, jenkinsMaxConn, jenkinsAdminUsername, jenkinsAdminPassword)
|
||||
|
||||
Reference in New Issue
Block a user