未验证 提交 f22e8ea9 编写于 作者: K KubeSphere CI Bot 提交者: GitHub

Merge pull request #670 from runzexia/bitbucket-support

Pipeline Support Bitbucket Scm
...@@ -350,6 +350,25 @@ The last one is encrypted info, such as the password of the username-password ty ...@@ -350,6 +350,25 @@ The last one is encrypted info, such as the password of the username-password ty
Returns(http.StatusOK, RespOK, []devops.SCMOrg{}). Returns(http.StatusOK, RespOK, []devops.SCMOrg{}).
Writes([]devops.SCMOrg{})) Writes([]devops.SCMOrg{}))
// match "/blue/rest/organizations/jenkins/scm/%s/servers/"
webservice.Route(webservice.GET("/scms/{scm}/servers").
To(devopsapi.GetSCMServers).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsScmTag}).
Doc("List all servers in the jenkins.").
Param(webservice.PathParameter("scm", "The ID of the source configuration management (SCM).")).
Returns(http.StatusOK, RespOK, []devops.SCMServer{}).
Writes([]devops.SCMServer{}))
// match "/blue/rest/organizations/jenkins/scm/%s/servers/"
webservice.Route(webservice.POST("/scms/{scm}/servers").
To(devopsapi.CreateSCMServers).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsScmTag}).
Doc("Create scm server in the jenkins.").
Param(webservice.PathParameter("scm", "The ID of the source configuration management (SCM).")).
Reads(devops.CreateScmServerReq{}).
Returns(http.StatusOK, RespOK, devops.SCMServer{}).
Writes(devops.SCMServer{}))
// match "/blue/rest/organizations/jenkins/scm/{scm}/organizations/{organization}/repositories/?credentialId=&pageNumber&pageSize=" // match "/blue/rest/organizations/jenkins/scm/{scm}/organizations/{organization}/repositories/?credentialId=&pageNumber&pageSize="
webservice.Route(webservice.GET("/scms/{scm}/organizations/{organization}/repositories"). webservice.Route(webservice.GET("/scms/{scm}/organizations/{organization}/repositories").
To(devopsapi.GetOrgRepo). To(devopsapi.GetOrgRepo).
......
...@@ -141,6 +141,32 @@ func GetStepLog(req *restful.Request, resp *restful.Response) { ...@@ -141,6 +141,32 @@ func GetStepLog(req *restful.Request, resp *restful.Response) {
resp.Write(res) resp.Write(res)
} }
func GetSCMServers(req *restful.Request, resp *restful.Response) {
scmId := req.PathParameter("scm")
res, err := devops.GetSCMServers(scmId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func CreateSCMServers(req *restful.Request, resp *restful.Response) {
scmId := req.PathParameter("scm")
res, err := devops.CreateSCMServers(scmId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func Validate(req *restful.Request, resp *restful.Response) { func Validate(req *restful.Request, resp *restful.Response) {
scmId := req.PathParameter("scm") scmId := req.PathParameter("scm")
......
...@@ -135,6 +135,30 @@ func GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, req *ht ...@@ -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) { func Validate(scmId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkins.Server+ValidateUrl, scmId) baseUrl := fmt.Sprintf(jenkins.Server+ValidateUrl, scmId)
log.Info("Jenkins-url: " + baseUrl) log.Info("Jenkins-url: " + baseUrl)
...@@ -731,7 +755,7 @@ func jenkinsClient(baseUrl string, req *http.Request) ([]byte, http.Header, erro ...@@ -731,7 +755,7 @@ func jenkinsClient(baseUrl string, req *http.Request) ([]byte, http.Header, erro
log.Errorf("%+v", string(resBody)) log.Errorf("%+v", string(resBody))
jkerr := new(JkError) jkerr := new(JkError)
jkerr.Code = resp.StatusCode jkerr.Code = resp.StatusCode
jkerr.Message = http.StatusText(resp.StatusCode) jkerr.Message = string(resBody)
return nil, nil, jkerr return nil, nil, jkerr
} }
......
...@@ -260,6 +260,19 @@ type SCMOrg struct { ...@@ -260,6 +260,19 @@ type SCMOrg struct {
Name string `json:"name,omitempty" description:"organization name"` Name string `json:"name,omitempty" description:"organization name"`
} }
type SCMServer struct {
Class string `json:"_class,omitempty" description:"It’s 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:"It’s 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 // GetOrgRepo
type OrgRepo struct { type OrgRepo struct {
Class string `json:"_class,omitempty" description:"It’s a fully qualified name and is an identifier of the producer of this resource's capability."` Class string `json:"_class,omitempty" description:"It’s a fully qualified name and is an identifier of the producer of this resource's capability."`
...@@ -721,6 +734,11 @@ type CheckPlayload struct { ...@@ -721,6 +734,11 @@ type CheckPlayload struct {
Abort bool `json:"abort,omitempty" description:"abort or not"` 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 { type CheckPlayloadParameters struct {
Name string `json:"name,omitempty" description:"name"` Name string `json:"name,omitempty" description:"name"`
Value string `json:"value,omitempty" description:"value"` Value string `json:"value,omitempty" description:"value"`
......
...@@ -110,7 +110,7 @@ func Test_NoScmPipelineConfig_Param(t *testing.T) { ...@@ -110,7 +110,7 @@ func Test_NoScmPipelineConfig_Param(t *testing.T) {
Name: "", Name: "",
Description: "for test", Description: "for test",
Jenkinsfile: "node{echo 'hello'}", Jenkinsfile: "node{echo 'hello'}",
Parameters: []*Parameter{ Parameters: &Parameters{
&Parameter{ &Parameter{
Name: "d", Name: "d",
DefaultValue: "a\nb", DefaultValue: "a\nb",
...@@ -123,7 +123,7 @@ func Test_NoScmPipelineConfig_Param(t *testing.T) { ...@@ -123,7 +123,7 @@ func Test_NoScmPipelineConfig_Param(t *testing.T) {
Name: "", Name: "",
Description: "for test", Description: "for test",
Jenkinsfile: "node{echo 'hello'}", Jenkinsfile: "node{echo 'hello'}",
Parameters: []*Parameter{ Parameters: &Parameters{
&Parameter{ &Parameter{
Name: "a", Name: "a",
DefaultValue: "abc", DefaultValue: "abc",
...@@ -355,7 +355,28 @@ func Test_MultiBranchPipelineConfig_Source(t *testing.T) { ...@@ -355,7 +355,28 @@ func Test_MultiBranchPipelineConfig_Source(t *testing.T) {
ApiUri: "https://api.github.com", ApiUri: "https://api.github.com",
DiscoverBranches: 1, DiscoverBranches: 1,
DiscoverPRFromOrigin: 2, DiscoverPRFromOrigin: 2,
DiscoverPRFromForks: &GithubDiscoverPRFromForks{ DiscoverPRFromForks: &DiscoverPRFromForks{
Strategy: 1,
Trust: 1,
},
},
},
&MultiBranchPipeline{
Name: "",
Description: "for test",
ScriptPath: "Jenkinsfile",
SourceType: "bitbucket_server",
TimerTrigger: &TimerTrigger{
Interval: "12345566",
},
BitbucketServerSource: &BitbucketServerSource{
Owner: "kubesphere",
Repo: "devops",
CredentialId: "github",
ApiUri: "https://api.github.com",
DiscoverBranches: 1,
DiscoverPRFromOrigin: 2,
DiscoverPRFromForks: &DiscoverPRFromForks{
Strategy: 1, Strategy: 1,
Trust: 1, Trust: 1,
}, },
...@@ -439,7 +460,7 @@ func Test_MultiBranchPipelineCloneConfig(t *testing.T) { ...@@ -439,7 +460,7 @@ func Test_MultiBranchPipelineCloneConfig(t *testing.T) {
ApiUri: "https://api.github.com", ApiUri: "https://api.github.com",
DiscoverBranches: 1, DiscoverBranches: 1,
DiscoverPRFromOrigin: 2, DiscoverPRFromOrigin: 2,
DiscoverPRFromForks: &GithubDiscoverPRFromForks{ DiscoverPRFromForks: &DiscoverPRFromForks{
Strategy: 1, Strategy: 1,
Trust: 1, Trust: 1,
}, },
...@@ -496,7 +517,7 @@ func Test_MultiBranchPipelineRegexFilter(t *testing.T) { ...@@ -496,7 +517,7 @@ func Test_MultiBranchPipelineRegexFilter(t *testing.T) {
ApiUri: "https://api.github.com", ApiUri: "https://api.github.com",
DiscoverBranches: 1, DiscoverBranches: 1,
DiscoverPRFromOrigin: 2, DiscoverPRFromOrigin: 2,
DiscoverPRFromForks: &GithubDiscoverPRFromForks{ DiscoverPRFromForks: &DiscoverPRFromForks{
Strategy: 1, Strategy: 1,
Trust: 1, Trust: 1,
}, },
......
...@@ -44,6 +44,8 @@ const ( ...@@ -44,6 +44,8 @@ const (
CheckPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/runs/%s/nodes/%s/steps/%s/" 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/?" 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/?" 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" ValidateUrl = "/blue/rest/organizations/jenkins/scm/%s/validate"
GetSCMOrgUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/?" GetSCMOrgUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/?"
GetOrgRepoUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/%s/repositories/?" GetOrgRepoUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/%s/repositories/?"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册