Merge pull request #670 from runzexia/bitbucket-support
Pipeline Support Bitbucket Scm
This commit is contained in:
@@ -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{}).
|
||||
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="
|
||||
webservice.Route(webservice.GET("/scms/{scm}/organizations/{organization}/repositories").
|
||||
To(devopsapi.GetOrgRepo).
|
||||
|
||||
@@ -141,6 +141,32 @@ func GetStepLog(req *restful.Request, resp *restful.Response) {
|
||||
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) {
|
||||
scmId := req.PathParameter("scm")
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -260,6 +260,19 @@ type SCMOrg struct {
|
||||
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
|
||||
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."`
|
||||
@@ -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"`
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -110,7 +110,7 @@ func Test_NoScmPipelineConfig_Param(t *testing.T) {
|
||||
Name: "",
|
||||
Description: "for test",
|
||||
Jenkinsfile: "node{echo 'hello'}",
|
||||
Parameters: []*Parameter{
|
||||
Parameters: &Parameters{
|
||||
&Parameter{
|
||||
Name: "d",
|
||||
DefaultValue: "a\nb",
|
||||
@@ -123,7 +123,7 @@ func Test_NoScmPipelineConfig_Param(t *testing.T) {
|
||||
Name: "",
|
||||
Description: "for test",
|
||||
Jenkinsfile: "node{echo 'hello'}",
|
||||
Parameters: []*Parameter{
|
||||
Parameters: &Parameters{
|
||||
&Parameter{
|
||||
Name: "a",
|
||||
DefaultValue: "abc",
|
||||
@@ -355,7 +355,28 @@ func Test_MultiBranchPipelineConfig_Source(t *testing.T) {
|
||||
ApiUri: "https://api.github.com",
|
||||
DiscoverBranches: 1,
|
||||
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,
|
||||
Trust: 1,
|
||||
},
|
||||
@@ -439,7 +460,7 @@ func Test_MultiBranchPipelineCloneConfig(t *testing.T) {
|
||||
ApiUri: "https://api.github.com",
|
||||
DiscoverBranches: 1,
|
||||
DiscoverPRFromOrigin: 2,
|
||||
DiscoverPRFromForks: &GithubDiscoverPRFromForks{
|
||||
DiscoverPRFromForks: &DiscoverPRFromForks{
|
||||
Strategy: 1,
|
||||
Trust: 1,
|
||||
},
|
||||
@@ -496,7 +517,7 @@ func Test_MultiBranchPipelineRegexFilter(t *testing.T) {
|
||||
ApiUri: "https://api.github.com",
|
||||
DiscoverBranches: 1,
|
||||
DiscoverPRFromOrigin: 2,
|
||||
DiscoverPRFromForks: &GithubDiscoverPRFromForks{
|
||||
DiscoverPRFromForks: &DiscoverPRFromForks{
|
||||
Strategy: 1,
|
||||
Trust: 1,
|
||||
},
|
||||
|
||||
@@ -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/?"
|
||||
|
||||
Reference in New Issue
Block a user