get & create scm server in jenkinsfile

Signed-off-by: runzexia <runzexia@yunify.com>
This commit is contained in:
runzexia
2019-08-26 14:22:39 +08:00
parent 1684998299
commit 45ab9286a2
5 changed files with 90 additions and 1 deletions

View File

@@ -135,6 +135,30 @@ func GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, req *ht
}
func GetSCMServers(scmId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+GetSCMServersUrl, scmId)
log.Info("Jenkins-url: " + baseUrl)
req.Method = http.MethodGet
resBody, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return resBody, err
}
func CreateSCMServers(scmId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+CreateSCMServersUrl, scmId)
log.Info("Jenkins-url: " + baseUrl)
req.Method = http.MethodPost
resBody, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return resBody, err
}
func Validate(scmId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+ValidateUrl, scmId)
log.Info("Jenkins-url: " + baseUrl)
@@ -731,7 +755,7 @@ func jenkinsClient(baseUrl string, req *http.Request) ([]byte, http.Header, erro
log.Errorf("%+v", string(resBody))
jkerr := new(JkError)
jkerr.Code = resp.StatusCode
jkerr.Message = http.StatusText(resp.StatusCode)
jkerr.Message = string(resBody)
return nil, nil, jkerr
}