add jenkins pre-check & fix jenkins flag

Signed-off-by: soulseen <sunzhu@yunify.com>
This commit is contained in:
soulseen
2019-05-05 22:37:01 +08:00
committed by zryfish
parent 2857071bdd
commit a57947fd45
5 changed files with 33 additions and 6 deletions

View File

@@ -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) {

View File

@@ -49,4 +49,5 @@ const (
ToJsonUrl = "/pipeline-model-converter/toJson"
GetNotifyCommitUrl = "/git/notifyCommit/?"
GithubWebhookUrl = "/github-webhook/"
LoginUrl = "/j_acegi_security_check"
)