Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
78f2dab1
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
78f2dab1
编写于
4月 24, 2019
作者:
S
soulseen
提交者:
zryfish
4月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add jenkins api & log
Signed-off-by:
N
soulseen
<
sunzhu@yunify.com
>
上级
e64e8bb9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
101 addition
and
10 deletion
+101
-10
pkg/apis/devops/v1alpha2/register.go
pkg/apis/devops/v1alpha2/register.go
+29
-6
pkg/apiserver/devops/devops.go
pkg/apiserver/devops/devops.go
+25
-2
pkg/models/devops/devops.go
pkg/models/devops/devops.go
+45
-2
pkg/models/devops/urlconfig.go
pkg/models/devops/urlconfig.go
+2
-0
未找到文件。
pkg/apis/devops/v1alpha2/register.go
浏览文件 @
78f2dab1
...
...
@@ -53,13 +53,17 @@ func addWebService(c *restful.Container) error {
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Search DevOps resource."
)
.
Param
(
webservice
.
QueryParameter
(
"q"
,
"query pipelines"
)
.
Required
(
false
))
.
Required
(
false
)
.
DataFormat
(
"q=%s"
))
.
Param
(
webservice
.
QueryParameter
(
"filter"
,
"filter resource"
)
.
Required
(
false
))
.
Required
(
false
)
.
DataFormat
(
"filter=%s"
))
.
Param
(
webservice
.
QueryParameter
(
"start"
,
"start page"
)
.
Required
(
false
))
.
Required
(
false
)
.
DataFormat
(
"start=%d"
))
.
Param
(
webservice
.
QueryParameter
(
"limit"
,
"limit count"
)
.
Required
(
false
)))
Required
(
false
)
.
DataFormat
(
"limit=%d"
)))
// match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/"
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/runs"
)
.
...
...
@@ -69,9 +73,11 @@ func addWebService(c *restful.Container) error {
Param
(
webservice
.
PathParameter
(
"pipelineName"
,
"pipeline name"
))
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
Param
(
webservice
.
QueryParameter
(
"start"
,
"start page"
)
.
Required
(
false
))
.
Required
(
false
)
.
DataFormat
(
"start=%d"
))
.
Param
(
webservice
.
QueryParameter
(
"limit"
,
"limit count"
)
.
Required
(
false
)))
Required
(
false
)
.
DataFormat
(
"limit=%d"
)))
// match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/"
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}"
)
.
...
...
@@ -113,6 +119,23 @@ func addWebService(c *restful.Container) error {
DataFormat
(
"start=%d"
)
.
DefaultValue
(
"start=0"
)))
// match "/blue/rest/organizations/jenkins/scm/github/validate/"
webservice
.
Route
(
webservice
.
PUT
(
"/devops/scm/{scmId}/validate"
)
.
To
(
devops
.
Validate
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Validate Github personal access token."
)
.
Param
(
webservice
.
PathParameter
(
"scmId"
,
"SCM id"
)))
// match "/blue/rest/organizations/jenkins/scm/{scmId}/organizations/?credentialId=github"
webservice
.
Route
(
webservice
.
GET
(
"/devops/scm/{scmId}/organizations"
)
.
To
(
devops
.
GetOrgSCM
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"List organizations of SCM"
)
.
Param
(
webservice
.
PathParameter
(
"scmId"
,
"SCM id"
))
.
Param
(
webservice
.
QueryParameter
(
"credentialId"
,
"credentialId for SCM"
)
.
Required
(
true
)
.
DataFormat
(
"credentialId=%s"
)))
c
.
Add
(
webservice
)
return
nil
...
...
pkg/apiserver/devops/devops.go
浏览文件 @
78f2dab1
...
...
@@ -19,6 +19,7 @@ package devops
import
(
"github.com/emicklei/go-restful"
log
"github.com/golang/glog"
"kubesphere.io/kubesphere/pkg/errors"
"kubesphere.io/kubesphere/pkg/models/devops"
"net/http"
...
...
@@ -59,7 +60,6 @@ func SearchPipelineRuns(req *restful.Request, resp *restful.Response) {
}
_
=
resp
.
WriteAsJson
(
res
)
}
func
GetPipelineRun
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
...
...
@@ -90,7 +90,6 @@ func GetPipelineRunNodes(req *restful.Request, resp *restful.Response) {
}
_
=
resp
.
WriteAsJson
(
res
)
}
func
GetStepLog
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
...
...
@@ -107,10 +106,34 @@ func GetStepLog(req *restful.Request, resp *restful.Response) {
return
}
_
,
_
=
resp
.
Write
(
res
)
}
func
Validate
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
scmId
:=
req
.
PathParameter
(
"scmId"
)
res
,
err
:=
devops
.
Validate
(
scmId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
}
_
,
_
=
resp
.
Write
(
res
)
}
func
GetOrgSCM
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
scmId
:=
req
.
PathParameter
(
"scmId"
)
res
,
err
:=
devops
.
GetOrgSCM
(
scmId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
}
_
=
resp
.
WriteAsJson
(
res
)
}
func
parseErr
(
err
error
,
resp
*
restful
.
Response
)
{
log
.
Error
(
err
)
if
jErr
,
ok
:=
err
.
(
*
devops
.
JkError
);
ok
{
_
=
resp
.
WriteHeaderAndEntity
(
jErr
.
Code
,
err
)
}
else
{
...
...
pkg/models/devops/devops.go
浏览文件 @
78f2dab1
...
...
@@ -42,6 +42,7 @@ func GetPipeline(projectName, pipelineName string, req *http.Request) (*Pipeline
resBody
,
err
:=
jenkinsClient
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
...
...
@@ -61,6 +62,7 @@ func SearchPipelines(req *http.Request) ([]interface{}, error) {
resBody
,
err
:=
jenkinsClient
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
...
...
@@ -80,6 +82,7 @@ func SearchPipelineRuns(projectName, pipelineName string, req *http.Request) ([]
resBody
,
err
:=
jenkinsClient
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
...
...
@@ -99,6 +102,7 @@ func GetPipelineRun(projectName, pipelineName, branchName, runId string, req *ht
resBody
,
err
:=
jenkinsClient
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
...
...
@@ -118,6 +122,7 @@ func GetPipelineRunNodes(projectName, pipelineName, branchName, runId string, re
resBody
,
err
:=
jenkinsClient
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
...
...
@@ -137,12 +142,46 @@ func GetStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId str
resBody
,
err
:=
jenkinsClient
(
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
(
JenkinsUrl
+
ValidateUrl
,
scmId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
resBody
,
err
:=
jenkinsClient
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
return
resBody
,
err
}
func
GetOrgSCM
(
scmId
string
,
req
*
http
.
Request
)
([]
interface
{},
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
JenkinsUrl
+
GetOrgSCMUrl
+
req
.
URL
.
RawQuery
,
scmId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
resBody
,
err
:=
jenkinsClient
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
var
res
[]
interface
{}
err
=
json
.
Unmarshal
(
resBody
,
&
res
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
return
res
,
err
}
// create jenkins request
func
jenkinsClient
(
baseUrl
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
newReqUrl
,
err
:=
url
.
Parse
(
baseUrl
)
...
...
@@ -168,10 +207,14 @@ func jenkinsClient(baseUrl string, req *http.Request) ([]byte, error) {
defer
resp
.
Body
.
Close
()
resBody
,
_
:=
getRespBody
(
resp
)
log
.
Info
(
string
(
resBody
))
if
resp
.
StatusCode
>=
http
.
StatusBadRequest
{
jkerr
:=
new
(
JkError
)
_
=
json
.
Unmarshal
(
resBody
,
jkerr
)
log
.
Error
(
nil
,
jkerr
)
err
=
json
.
Unmarshal
(
resBody
,
jkerr
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
return
nil
,
jkerr
}
...
...
pkg/models/devops/urlconfig.go
浏览文件 @
78f2dab1
...
...
@@ -25,4 +25,6 @@ const (
GetPipelineRunUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/"
GetPipelineRunNodesUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/?"
GetStepLogUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/%s/log/?"
ValidateUrl
=
"/blue/rest/organizations/jenkins/scm/%s/validate"
GetOrgSCMUrl
=
"/blue/rest/organizations/jenkins/scm/%s/organizations/?"
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录