Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
KubeSphere
kubesphere
提交
45ab9286
K
kubesphere
项目概览
KubeSphere
/
kubesphere
通知
144
Star
32
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
45ab9286
编写于
8月 26, 2019
作者:
R
runzexia
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
get & create scm server in jenkinsfile
Signed-off-by:
N
runzexia
<
runzexia@yunify.com
>
上级
16849982
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
90 addition
and
1 deletion
+90
-1
pkg/apis/devops/v1alpha2/register.go
pkg/apis/devops/v1alpha2/register.go
+19
-0
pkg/apiserver/devops/devops.go
pkg/apiserver/devops/devops.go
+26
-0
pkg/models/devops/devops.go
pkg/models/devops/devops.go
+25
-1
pkg/models/devops/json.go
pkg/models/devops/json.go
+18
-0
pkg/models/devops/urlconfig.go
pkg/models/devops/urlconfig.go
+2
-0
未找到文件。
pkg/apis/devops/v1alpha2/register.go
浏览文件 @
45ab9286
...
...
@@ -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
)
.
...
...
pkg/apiserver/devops/devops.go
浏览文件 @
45ab9286
...
...
@@ -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"
)
...
...
pkg/models/devops/devops.go
浏览文件 @
45ab9286
...
...
@@ -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
}
...
...
pkg/models/devops/json.go
浏览文件 @
45ab9286
...
...
@@ -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"`
...
...
pkg/models/devops/urlconfig.go
浏览文件 @
45ab9286
...
...
@@ -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/?"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录