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
}

View File

@@ -260,6 +260,19 @@ type SCMOrg struct {
Name string `json:"name,omitempty" description:"organization name"`
}
type SCMServer struct {
Class string `json:"_class,omitempty" description:"Its a fully qualified name and is an identifier of the producer of this resource's capability."`
Links struct {
Self struct {
Class string `json:"_class,omitempty" description:"Its a fully qualified name and is an identifier of the producer of this resource's capability."`
Href string `json:"href,omitempty" description:"self url in api"`
} `json:"self,omitempty" description:"scm server self info"`
} `json:"_links,omitempty" description:"references the reachable path to this resource"`
ID string `json:"id,omitempty" description:"server id of scm server"`
Name string `json:"name,omitempty" description:"name of scm server"`
ApiURL string `json:"apiUrl,omitempty" description:"url of scm server"`
}
// GetOrgRepo
type OrgRepo struct {
Class string `json:"_class,omitempty" description:"Its a fully qualified name and is an identifier of the producer of this resource's capability."`
@@ -721,6 +734,11 @@ type CheckPlayload struct {
Abort bool `json:"abort,omitempty" description:"abort or not"`
}
type CreateScmServerReq struct {
Name string `json:"name,omitempty" description:"name of scm server"`
ApiURL string `json:"apiUrl,omitempty" description:"url of scm server"`
}
type CheckPlayloadParameters struct {
Name string `json:"name,omitempty" description:"name"`
Value string `json:"value,omitempty" description:"value"`

View File

@@ -44,6 +44,8 @@ const (
CheckPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/runs/%s/nodes/%s/steps/%s/"
GetBranchNodeStepsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/nodes/%s/steps/?"
GetNodeStepsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/runs/%s/nodes/%s/steps/?"
GetSCMServersUrl = "/blue/rest/organizations/jenkins/scm/%s/servers/"
CreateSCMServersUrl = "/blue/rest/organizations/jenkins/scm/%s/servers/"
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/?"