Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
0e50a93e
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看板
未验证
提交
0e50a93e
编写于
5月 08, 2019
作者:
不
不羁
提交者:
GitHub
5月 08, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into master
上级
dbb02bd0
8ba8078a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
632 addition
and
82 deletion
+632
-82
pkg/apis/devops/v1alpha2/register.go
pkg/apis/devops/v1alpha2/register.go
+160
-10
pkg/apiserver/devops/devops.go
pkg/apiserver/devops/devops.go
+162
-15
pkg/models/devops/devops.go
pkg/models/devops/devops.go
+218
-16
pkg/models/devops/json.go
pkg/models/devops/json.go
+43
-1
pkg/models/devops/urlconfig.go
pkg/models/devops/urlconfig.go
+22
-14
pkg/simple/client/admin_jenkins/jenkins.go
pkg/simple/client/admin_jenkins/jenkins.go
+27
-26
未找到文件。
pkg/apis/devops/v1alpha2/register.go
浏览文件 @
0e50a93e
...
...
@@ -307,7 +307,7 @@ func addWebService(c *restful.Container) error {
// match "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log/?start=0"
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log"
)
.
To
(
devopsapi
.
GetStepLog
)
.
To
(
devopsapi
.
Get
Branch
StepLog
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Get pipelines step log."
)
.
Produces
(
"text/plain; charset=utf-8"
)
.
...
...
@@ -322,6 +322,22 @@ func addWebService(c *restful.Container) error {
DataFormat
(
"start=%d"
)
.
DefaultValue
(
"start=0"
)))
// match "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log/?start=0"
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log"
)
.
To
(
devopsapi
.
GetStepLog
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Get pipelines step log."
)
.
Produces
(
"text/plain; charset=utf-8"
)
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
Param
(
webservice
.
PathParameter
(
"pipelineName"
,
"pipeline name"
))
.
Param
(
webservice
.
PathParameter
(
"runId"
,
"pipeline runs id"
))
.
Param
(
webservice
.
PathParameter
(
"nodeId"
,
"pipeline runs node id"
))
.
Param
(
webservice
.
PathParameter
(
"stepId"
,
"pipeline runs step id"
))
.
Param
(
webservice
.
QueryParameter
(
"start"
,
"start"
)
.
Required
(
true
)
.
DataFormat
(
"start=%d"
)
.
DefaultValue
(
"start=0"
)))
// match "/blue/rest/organizations/jenkins/scm/github/validate/"
webservice
.
Route
(
webservice
.
PUT
(
"/devops/scm/{scmId}/validate"
)
.
To
(
devopsapi
.
Validate
)
.
...
...
@@ -364,7 +380,7 @@ func addWebService(c *restful.Container) error {
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/stop/
webservice
.
Route
(
webservice
.
PUT
(
"/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/stop"
)
.
To
(
devopsapi
.
StopPipeline
)
.
To
(
devopsapi
.
Stop
Branch
Pipeline
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Stop pipeline in running"
)
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
...
...
@@ -382,9 +398,28 @@ func addWebService(c *restful.Container) error {
Returns
(
http
.
StatusOK
,
RespOK
,
devops
.
StopPipe
{})
.
Writes
(
devops
.
StopPipe
{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/runs/{runId}/stop/
webservice
.
Route
(
webservice
.
PUT
(
"/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/stop"
)
.
To
(
devopsapi
.
StopPipeline
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Stop pipeline in running"
)
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
Param
(
webservice
.
PathParameter
(
"pipelineName"
,
"pipeline name"
))
.
Param
(
webservice
.
PathParameter
(
"runId"
,
"pipeline runs id"
))
.
Param
(
webservice
.
QueryParameter
(
"blocking"
,
"stop and between each retries will sleep"
)
.
Required
(
false
)
.
DataFormat
(
"blocking=%t"
)
.
DefaultValue
(
"blocking=false"
))
.
Param
(
webservice
.
QueryParameter
(
"timeOutInSecs"
,
"the time of stop and between each retries sleep"
)
.
Required
(
false
)
.
DataFormat
(
"timeOutInSecs=%d"
)
.
DefaultValue
(
"timeOutInSecs=10"
))
.
Returns
(
http
.
StatusOK
,
RespOK
,
devops
.
StopPipe
{})
.
Writes
(
devops
.
StopPipe
{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/Replay/
webservice
.
Route
(
webservice
.
POST
(
"/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/replay"
)
.
To
(
devopsapi
.
ReplayPipeline
)
.
To
(
devopsapi
.
Replay
Branch
Pipeline
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Replay pipeline"
)
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
...
...
@@ -394,9 +429,20 @@ func addWebService(c *restful.Container) error {
Returns
(
http
.
StatusOK
,
RespOK
,
devops
.
ReplayPipe
{})
.
Writes
(
devops
.
ReplayPipe
{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/runs/{runId}/Replay/
webservice
.
Route
(
webservice
.
POST
(
"/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/replay"
)
.
To
(
devopsapi
.
ReplayPipeline
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Replay pipeline"
)
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
Param
(
webservice
.
PathParameter
(
"pipelineName"
,
"pipeline name"
))
.
Param
(
webservice
.
PathParameter
(
"runId"
,
"pipeline runs id"
))
.
Returns
(
http
.
StatusOK
,
RespOK
,
devops
.
ReplayPipe
{})
.
Writes
(
devops
.
ReplayPipe
{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/log/?start=0
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/log"
)
.
To
(
devopsapi
.
GetRunLog
)
.
To
(
devopsapi
.
Get
Branch
RunLog
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Get Pipelines run log."
)
.
Produces
(
"text/plain; charset=utf-8"
)
.
...
...
@@ -409,9 +455,23 @@ func addWebService(c *restful.Container) error {
DataFormat
(
"start=%d"
)
.
DefaultValue
(
"start=0"
)))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/log/?start=0
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/log"
)
.
To
(
devopsapi
.
GetRunLog
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Get Pipelines run log."
)
.
Produces
(
"text/plain; charset=utf-8"
)
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
Param
(
webservice
.
PathParameter
(
"pipelineName"
,
"pipeline name"
))
.
Param
(
webservice
.
PathParameter
(
"runId"
,
"pipeline runs id"
))
.
Param
(
webservice
.
QueryParameter
(
"start"
,
"start"
)
.
Required
(
true
)
.
DataFormat
(
"start=%d"
)
.
DefaultValue
(
"start=0"
)))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/artifacts
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/artifacts"
)
.
To
(
devopsapi
.
GetArtifacts
)
.
To
(
devopsapi
.
Get
Branch
Artifacts
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Get pipeline artifacts."
)
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
...
...
@@ -427,6 +487,23 @@ func addWebService(c *restful.Container) error {
Returns
(
http
.
StatusOK
,
"The filed of
\"
Url
\"
in response can download artifacts"
,
[]
devops
.
Artifacts
{})
.
Writes
([]
devops
.
Artifacts
{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/artifacts
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/artifacts"
)
.
To
(
devopsapi
.
GetArtifacts
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Get pipeline artifacts."
)
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
Param
(
webservice
.
PathParameter
(
"pipelineName"
,
"pipeline name"
))
.
Param
(
webservice
.
PathParameter
(
"runId"
,
"pipeline runs id"
))
.
Param
(
webservice
.
QueryParameter
(
"start"
,
"start page"
)
.
Required
(
false
)
.
DataFormat
(
"start=%d"
))
.
Param
(
webservice
.
QueryParameter
(
"limit"
,
"limit count"
)
.
Required
(
false
)
.
DataFormat
(
"limit=%d"
))
.
Returns
(
http
.
StatusOK
,
"The filed of
\"
Url
\"
in response can download artifacts"
,
[]
devops
.
Artifacts
{})
.
Writes
([]
devops
.
Artifacts
{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/?filter=&start&limit=
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/branches"
)
.
To
(
devopsapi
.
GetPipeBranch
)
.
...
...
@@ -448,7 +525,7 @@ func addWebService(c *restful.Container) error {
// /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}
webservice
.
Route
(
webservice
.
POST
(
"/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}"
)
.
To
(
devopsapi
.
CheckPipeline
)
.
To
(
devopsapi
.
Check
Branch
Pipeline
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Pauses pipeline execution and allows the user to interact and control the flow of the build."
)
.
Reads
(
devops
.
CheckPlayload
{})
.
...
...
@@ -460,6 +537,19 @@ func addWebService(c *restful.Container) error {
Param
(
webservice
.
PathParameter
(
"nodeId"
,
"pipeline node id"
))
.
Param
(
webservice
.
PathParameter
(
"stepId"
,
"pipeline step id"
)))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}
webservice
.
Route
(
webservice
.
POST
(
"/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}"
)
.
To
(
devopsapi
.
CheckPipeline
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Pauses pipeline execution and allows the user to interact and control the flow of the build."
)
.
Reads
(
devops
.
CheckPlayload
{})
.
Produces
(
"text/plain; charset=utf-8"
)
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
Param
(
webservice
.
PathParameter
(
"pipelineName"
,
"pipeline name"
))
.
Param
(
webservice
.
PathParameter
(
"runId"
,
"pipeline runs id"
))
.
Param
(
webservice
.
PathParameter
(
"nodeId"
,
"pipeline node id"
))
.
Param
(
webservice
.
PathParameter
(
"stepId"
,
"pipeline step id"
)))
// match /job/project-8QnvykoJw4wZ/job/test-1/indexing/consoleText
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/console/log"
)
.
To
(
devopsapi
.
GetConsoleLog
)
.
...
...
@@ -495,7 +585,7 @@ func addWebService(c *restful.Container) error {
// match /pipeline_status/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/?limit=
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/status"
)
.
To
(
devopsapi
.
GetStepsStatus
)
.
To
(
devopsapi
.
Get
Branch
StepsStatus
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Get pipeline steps status."
)
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
...
...
@@ -509,6 +599,21 @@ func addWebService(c *restful.Container) error {
Returns
(
http
.
StatusOK
,
RespOK
,
[]
devops
.
QueuedBlueRun
{})
.
Writes
([]
devops
.
QueuedBlueRun
{}))
// match /pipeline_status/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/nodes/?limit=
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/status"
)
.
To
(
devopsapi
.
GetStepsStatus
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Get pipeline steps status."
)
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
Param
(
webservice
.
PathParameter
(
"pipelineName"
,
"pipeline name"
))
.
Param
(
webservice
.
PathParameter
(
"runId"
,
"pipeline run name"
))
.
Param
(
webservice
.
PathParameter
(
"nodeId"
,
"pipeline node id"
))
.
Param
(
webservice
.
QueryParameter
(
"limit"
,
"limit count"
)
.
Required
(
true
)
.
DataFormat
(
"limit=%d"
))
.
Returns
(
http
.
StatusOK
,
RespOK
,
[]
devops
.
QueuedBlueRun
{})
.
Writes
([]
devops
.
QueuedBlueRun
{}))
// match /crumbIssuer/api/json/
webservice
.
Route
(
webservice
.
GET
(
"/devops/crumbissuer"
)
.
To
(
devopsapi
.
GetCrumb
)
.
...
...
@@ -579,7 +684,7 @@ func addWebService(c *restful.Container) error {
// match /blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?limit=
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps"
)
.
To
(
devopsapi
.
GetNodeSteps
)
.
To
(
devopsapi
.
Get
Branch
NodeSteps
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Get steps in node."
)
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
...
...
@@ -587,6 +692,21 @@ func addWebService(c *restful.Container) error {
Param
(
webservice
.
PathParameter
(
"branchName"
,
"pipeline branch name"
))
.
Param
(
webservice
.
PathParameter
(
"runId"
,
"pipeline run id"
))
.
Param
(
webservice
.
PathParameter
(
"nodeId"
,
"pipeline node id"
))
.
Param
(
webservice
.
QueryParameter
(
"limit"
,
"limit count"
)
.
Required
(
false
)
.
DataFormat
(
"limit=%d"
))
.
Returns
(
http
.
StatusOK
,
RespOK
,
[]
devops
.
NodeSteps
{})
.
Writes
([]
devops
.
NodeSteps
{}))
// match /blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/%s/steps/?limit=
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps"
)
.
To
(
devopsapi
.
GetNodeSteps
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Get steps in node."
)
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
Param
(
webservice
.
PathParameter
(
"pipelineName"
,
"pipeline name"
))
.
Param
(
webservice
.
PathParameter
(
"runId"
,
"pipeline run id"
))
.
Param
(
webservice
.
PathParameter
(
"nodeId"
,
"pipeline node id"
))
.
Param
(
webservice
.
QueryParameter
(
"limit"
,
"limit count"
)
.
Required
(
false
)
.
DataFormat
(
"limit=%d"
))
.
...
...
@@ -601,7 +721,7 @@ func addWebService(c *restful.Container) error {
Produces
(
"application/json"
,
"charset=utf-8"
)
.
Doc
(
"Json to Jenkinsfile."
)
.
Reads
(
devops
.
ReqJson
{})
.
Returns
(
http
.
StatusOK
,
RespOK
,
devops
.
NodeSteps
{})
.
Returns
(
http
.
StatusOK
,
RespOK
,
devops
.
NodeSteps
{})
.
Writes
(
devops
.
ResJenkinsfile
{}))
// match /pipeline-model-converter/toJson
...
...
@@ -612,7 +732,7 @@ func addWebService(c *restful.Container) error {
Produces
(
"application/json"
,
"charset=utf-8"
)
.
Doc
(
"Jenkinsfile to Json."
)
.
Reads
(
devops
.
ReqJenkinsfile
{})
.
Returns
(
http
.
StatusOK
,
RespOK
,
devops
.
ResJson
{})
.
Returns
(
http
.
StatusOK
,
RespOK
,
devops
.
ResJson
{})
.
Writes
(
devops
.
ResJson
{}))
// match /git/notifyCommit/?url=
...
...
@@ -641,6 +761,36 @@ func addWebService(c *restful.Container) error {
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"receive webhook request."
))
// in scm get all steps in nodes.
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodesdetail"
)
.
To
(
devopsapi
.
GetBranchNodesDetail
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Get pipeline nodes stages detail"
)
.
Param
(
webservice
.
PathParameter
(
"pipelineName"
,
"pipeline name"
))
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
Param
(
webservice
.
PathParameter
(
"branchName"
,
"pipeline branch name"
))
.
Param
(
webservice
.
PathParameter
(
"runId"
,
"pipeline runs id"
))
.
Param
(
webservice
.
QueryParameter
(
"limit"
,
"limit count"
)
.
Required
(
true
)
.
DataFormat
(
"limit=%d"
))
.
Returns
(
http
.
StatusOK
,
RespOK
,[]
devops
.
NodesDetail
{})
.
Writes
(
devops
.
NodesDetail
{}))
// out of scm get all steps in nodes.
webservice
.
Route
(
webservice
.
GET
(
"/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodesdetail"
)
.
To
(
devopsapi
.
GetNodesDetail
)
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
tags
)
.
Doc
(
"Get pipeline nodes stages detail"
)
.
Param
(
webservice
.
PathParameter
(
"pipelineName"
,
"pipeline name"
))
.
Param
(
webservice
.
PathParameter
(
"projectName"
,
"devops project name"
))
.
Param
(
webservice
.
PathParameter
(
"branchName"
,
"pipeline branch name"
))
.
Param
(
webservice
.
PathParameter
(
"runId"
,
"pipeline runs id"
))
.
Param
(
webservice
.
QueryParameter
(
"limit"
,
"limit count"
)
.
Required
(
true
)
.
DataFormat
(
"limit=%d"
))
.
Returns
(
http
.
StatusOK
,
RespOK
,[]
devops
.
NodesDetail
{})
.
Writes
(
devops
.
NodesDetail
{}))
c
.
Add
(
webservice
)
return
nil
...
...
pkg/apiserver/devops/devops.go
浏览文件 @
0e50a93e
...
...
@@ -96,7 +96,7 @@ func GetPipelineRunNodesbyBranch(req *restful.Request, resp *restful.Response) {
resp
.
Write
(
res
)
}
func
GetStepLog
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
func
Get
Branch
StepLog
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
branchName
:=
req
.
PathParameter
(
"branchName"
)
...
...
@@ -104,7 +104,22 @@ func GetStepLog(req *restful.Request, resp *restful.Response) {
nodeId
:=
req
.
PathParameter
(
"nodeId"
)
stepId
:=
req
.
PathParameter
(
"stepId"
)
res
,
err
:=
devops
.
GetStepLog
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
stepId
,
req
.
Request
)
res
,
err
:=
devops
.
GetBranchStepLog
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
stepId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
}
resp
.
Write
(
res
)
}
func
GetStepLog
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
nodeId
:=
req
.
PathParameter
(
"nodeId"
)
stepId
:=
req
.
PathParameter
(
"stepId"
)
res
,
err
:=
devops
.
GetStepLog
(
projectName
,
pipelineName
,
runId
,
nodeId
,
stepId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
...
...
@@ -152,13 +167,44 @@ func GetOrgRepo(req *restful.Request, resp *restful.Response) {
resp
.
Write
(
res
)
}
func
StopBranchPipeline
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
branchName
:=
req
.
PathParameter
(
"branchName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
res
,
err
:=
devops
.
StopBranchPipeline
(
projectName
,
pipelineName
,
branchName
,
runId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
}
resp
.
Header
()
.
Set
(
restful
.
HEADER_ContentType
,
restful
.
MIME_JSON
)
resp
.
Write
(
res
)
}
func
StopPipeline
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
res
,
err
:=
devops
.
StopPipeline
(
projectName
,
pipelineName
,
runId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
}
resp
.
Header
()
.
Set
(
restful
.
HEADER_ContentType
,
restful
.
MIME_JSON
)
resp
.
Write
(
res
)
}
func
ReplayBranchPipeline
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
branchName
:=
req
.
PathParameter
(
"branchName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
res
,
err
:=
devops
.
Stop
Pipeline
(
projectName
,
pipelineName
,
branchName
,
runId
,
req
.
Request
)
res
,
err
:=
devops
.
ReplayBranch
Pipeline
(
projectName
,
pipelineName
,
branchName
,
runId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
...
...
@@ -171,10 +217,9 @@ func StopPipeline(req *restful.Request, resp *restful.Response) {
func
ReplayPipeline
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
branchName
:=
req
.
PathParameter
(
"branchName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
res
,
err
:=
devops
.
ReplayPipeline
(
projectName
,
pipelineName
,
branchName
,
runId
,
req
.
Request
)
res
,
err
:=
devops
.
ReplayPipeline
(
projectName
,
pipelineName
,
runId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
...
...
@@ -184,13 +229,13 @@ func ReplayPipeline(req *restful.Request, resp *restful.Response) {
resp
.
Write
(
res
)
}
func
GetRunLog
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
func
Get
Branch
RunLog
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
branchName
:=
req
.
PathParameter
(
"branchName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
res
,
err
:=
devops
.
GetRunLog
(
projectName
,
pipelineName
,
branchName
,
runId
,
req
.
Request
)
res
,
err
:=
devops
.
Get
Branch
RunLog
(
projectName
,
pipelineName
,
branchName
,
runId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
...
...
@@ -199,13 +244,41 @@ func GetRunLog(req *restful.Request, resp *restful.Response) {
resp
.
Write
(
res
)
}
func
GetArtifacts
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
func
GetRunLog
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
res
,
err
:=
devops
.
GetRunLog
(
projectName
,
pipelineName
,
runId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
}
resp
.
Write
(
res
)
}
func
GetBranchArtifacts
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
branchName
:=
req
.
PathParameter
(
"branchName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
res
,
err
:=
devops
.
GetArtifacts
(
projectName
,
pipelineName
,
branchName
,
runId
,
req
.
Request
)
res
,
err
:=
devops
.
GetBranchArtifacts
(
projectName
,
pipelineName
,
branchName
,
runId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
}
resp
.
Header
()
.
Set
(
restful
.
HEADER_ContentType
,
restful
.
MIME_JSON
)
resp
.
Write
(
res
)
}
func
GetArtifacts
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
res
,
err
:=
devops
.
GetArtifacts
(
projectName
,
pipelineName
,
runId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
...
...
@@ -227,7 +300,7 @@ func GetPipeBranch(req *restful.Request, resp *restful.Response) {
resp
.
Write
(
res
)
}
func
CheckPipeline
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
func
Check
Branch
Pipeline
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
branchName
:=
req
.
PathParameter
(
"branchName"
)
...
...
@@ -235,7 +308,23 @@ func CheckPipeline(req *restful.Request, resp *restful.Response) {
nodeId
:=
req
.
PathParameter
(
"nodeId"
)
stepId
:=
req
.
PathParameter
(
"stepId"
)
res
,
err
:=
devops
.
CheckPipeline
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
stepId
,
req
.
Request
)
res
,
err
:=
devops
.
CheckBranchPipeline
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
stepId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
}
resp
.
Write
(
res
)
}
func
CheckPipeline
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
nodeId
:=
req
.
PathParameter
(
"nodeId"
)
stepId
:=
req
.
PathParameter
(
"stepId"
)
res
,
err
:=
devops
.
CheckPipeline
(
projectName
,
pipelineName
,
runId
,
nodeId
,
stepId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
...
...
@@ -285,14 +374,30 @@ func RunPipeline(req *restful.Request, resp *restful.Response) {
resp
.
Write
(
res
)
}
func
GetStepsStatus
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
func
Get
Branch
StepsStatus
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
branchName
:=
req
.
PathParameter
(
"branchName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
nodeId
:=
req
.
PathParameter
(
"nodeId"
)
res
,
err
:=
devops
.
GetStepsStatus
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
req
.
Request
)
res
,
err
:=
devops
.
GetBranchStepsStatus
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
}
resp
.
Header
()
.
Set
(
restful
.
HEADER_ContentType
,
restful
.
MIME_JSON
)
resp
.
Write
(
res
)
}
func
GetStepsStatus
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
nodeId
:=
req
.
PathParameter
(
"nodeId"
)
res
,
err
:=
devops
.
GetStepsStatus
(
projectName
,
pipelineName
,
runId
,
nodeId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
...
...
@@ -392,14 +497,29 @@ func GetPipelineRunNodes(req *restful.Request, resp *restful.Response) {
resp
.
Write
(
res
)
}
func
GetNodeSteps
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
func
Get
Branch
NodeSteps
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
branchName
:=
req
.
PathParameter
(
"branchName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
nodeId
:=
req
.
PathParameter
(
"nodeId"
)
res
,
err
:=
devops
.
GetNodeSteps
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
req
.
Request
)
res
,
err
:=
devops
.
GetBranchNodeSteps
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
}
resp
.
Header
()
.
Set
(
restful
.
HEADER_ContentType
,
restful
.
MIME_JSON
)
resp
.
Write
(
res
)
}
func
GetNodeSteps
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
nodeId
:=
req
.
PathParameter
(
"nodeId"
)
res
,
err
:=
devops
.
GetNodeSteps
(
projectName
,
pipelineName
,
runId
,
nodeId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
...
...
@@ -446,6 +566,33 @@ func GithubWebhook(req *restful.Request, resp *restful.Response) {
resp
.
Write
(
res
)
}
func
GetBranchNodesDetail
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
branchName
:=
req
.
PathParameter
(
"branchName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
res
,
err
:=
devops
.
GetBranchNodesDetail
(
projectName
,
pipelineName
,
branchName
,
runId
,
req
.
Request
)
if
err
!=
nil
{
parseErr
(
err
,
resp
)
return
}
resp
.
WriteAsJson
(
res
)
}
func
GetNodesDetail
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
projectName
:=
req
.
PathParameter
(
"projectName"
)
pipelineName
:=
req
.
PathParameter
(
"pipelineName"
)
runId
:=
req
.
PathParameter
(
"runId"
)
res
,
err
:=
devops
.
GetNodesDetail
(
projectName
,
pipelineName
,
runId
,
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
{
...
...
pkg/models/devops/devops.go
浏览文件 @
0e50a93e
...
...
@@ -19,6 +19,7 @@ package devops
import
(
"compress/gzip"
"encoding/json"
"fmt"
"github.com/PuerkitoBio/goquery"
log
"github.com/golang/glog"
...
...
@@ -28,9 +29,12 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/admin_jenkins"
"net/http"
"net/url"
"sync"
"time"
)
const
channelMaxCapacity
=
100
var
jenkins
*
gojenkins
.
Jenkins
func
PreCheckJenkins
()
{
...
...
@@ -102,8 +106,21 @@ func GetPipelineRunNodesbyBranch(projectName, pipelineName, branchName, runId st
return
res
,
err
}
func
GetStepLog
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
stepId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetStepLogUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
stepId
)
func
GetBranchStepLog
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
stepId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetBranchStepLogUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
stepId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
resBody
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
return
resBody
,
err
}
func
GetStepLog
(
projectName
,
pipelineName
,
runId
,
nodeId
,
stepId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetStepLogUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
runId
,
nodeId
,
stepId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
resBody
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
...
...
@@ -154,8 +171,21 @@ func GetOrgRepo(scmId, organizationId string, req *http.Request) ([]byte, error)
return
res
,
err
}
func
StopPipeline
(
projectName
,
pipelineName
,
branchName
,
runId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
StopPipelineUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
)
func
StopBranchPipeline
(
projectName
,
pipelineName
,
branchName
,
runId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
StopBranchPipelineUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
res
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
return
res
,
err
}
func
StopPipeline
(
projectName
,
pipelineName
,
runId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
StopPipelineUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
runId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
res
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
...
...
@@ -167,8 +197,8 @@ func StopPipeline(projectName, pipelineName, branchName, runId string, req *http
return
res
,
err
}
func
ReplayPipeline
(
projectName
,
pipelineName
,
branchName
,
runId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
ReplayPipelineUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
)
func
Replay
Branch
Pipeline
(
projectName
,
pipelineName
,
branchName
,
runId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
Replay
Branch
PipelineUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
res
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
...
...
@@ -180,8 +210,8 @@ func ReplayPipeline(projectName, pipelineName, branchName, runId string, req *ht
return
res
,
err
}
func
GetRunLog
(
projectName
,
pipelineName
,
branch
Name
,
runId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetRunLogUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branch
Name
,
runId
)
func
ReplayPipeline
(
projectName
,
pipeline
Name
,
runId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
ReplayPipelineUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipeline
Name
,
runId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
res
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
...
...
@@ -193,8 +223,47 @@ func GetRunLog(projectName, pipelineName, branchName, runId string, req *http.Re
return
res
,
err
}
func
GetArtifacts
(
projectName
,
pipelineName
,
branchName
,
runId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetArtifactsUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
)
func
GetBranchRunLog
(
projectName
,
pipelineName
,
branchName
,
runId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetBranchRunLogUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
res
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
return
res
,
err
}
func
GetRunLog
(
projectName
,
pipelineName
,
runId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetRunLogUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
runId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
res
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
return
res
,
err
}
func
GetBranchArtifacts
(
projectName
,
pipelineName
,
branchName
,
runId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetBranchArtifactsUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
res
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
return
res
,
err
}
func
GetArtifacts
(
projectName
,
pipelineName
,
runId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetArtifactsUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
runId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
res
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
...
...
@@ -219,8 +288,21 @@ func GetPipeBranch(projectName, pipelineName string, req *http.Request) ([]byte,
return
res
,
err
}
func
CheckPipeline
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
stepId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
CheckPipelineUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
stepId
)
func
CheckBranchPipeline
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
stepId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
CheckBranchPipelineUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
stepId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
resBody
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
return
resBody
,
err
}
func
CheckPipeline
(
projectName
,
pipelineName
,
runId
,
nodeId
,
stepId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
CheckPipelineUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
runId
,
nodeId
,
stepId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
resBody
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
...
...
@@ -271,8 +353,21 @@ func RunPipeline(projectName, pipelineName, branchName string, req *http.Request
return
res
,
err
}
func
GetStepsStatus
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetStepsStatusUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
)
func
GetBranchStepsStatus
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetBranchStepsStatusUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
res
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
return
res
,
err
}
func
GetStepsStatus
(
projectName
,
pipelineName
,
runId
,
nodeId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetStepsStatusUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
runId
,
nodeId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
res
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
...
...
@@ -375,8 +470,21 @@ func GetPipelineRunNodes(projectName, pipelineName, runId string, req *http.Requ
return
res
,
err
}
func
GetNodeSteps
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetNodeStepsUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
)
func
GetBranchNodeSteps
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetBranchNodeStepsUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
res
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
return
res
,
err
}
func
GetNodeSteps
(
projectName
,
pipelineName
,
runId
,
nodeId
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
baseUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetNodeStepsUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
runId
,
nodeId
)
log
.
Infof
(
"Jenkins-url: "
+
baseUrl
)
res
,
err
:=
sendJenkinsRequest
(
baseUrl
,
req
)
...
...
@@ -441,6 +549,100 @@ func GithubWebhook(req *http.Request) ([]byte, error) {
return
res
,
err
}
func
GetBranchNodesDetail
(
projectName
,
pipelineName
,
branchName
,
runId
string
,
req
*
http
.
Request
)
([]
NodesDetail
,
error
)
{
getNodesUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetBranchPipeRunNodesUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
branchName
,
runId
)
log
.
Infof
(
"getNodesUrl: "
+
getNodesUrl
)
var
wg
sync
.
WaitGroup
var
nodesDetails
[]
NodesDetail
stepChan
:=
make
(
chan
*
NodesStepsIndex
,
channelMaxCapacity
)
respNodes
,
err
:=
GetPipelineRunNodesbyBranch
(
projectName
,
pipelineName
,
branchName
,
runId
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
err
=
json
.
Unmarshal
(
respNodes
,
&
nodesDetails
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
// get all steps in nodes.
for
i
,
v
:=
range
nodesDetails
{
wg
.
Add
(
1
)
go
func
(
nodeId
string
,
index
int
)
{
var
steps
[]
NodeSteps
respSteps
,
err
:=
GetBranchNodeSteps
(
projectName
,
pipelineName
,
branchName
,
runId
,
nodeId
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
}
err
=
json
.
Unmarshal
(
respSteps
,
&
steps
)
stepChan
<-
&
NodesStepsIndex
{
index
,
steps
}
wg
.
Done
()
}(
v
.
ID
,
i
)
}
wg
.
Wait
()
close
(
stepChan
)
for
oneNodeSteps
:=
range
stepChan
{
if
oneNodeSteps
!=
nil
{
nodesDetails
[
oneNodeSteps
.
Id
]
.
Steps
=
append
(
nodesDetails
[
oneNodeSteps
.
Id
]
.
Steps
,
oneNodeSteps
.
Steps
...
)
}
}
return
nodesDetails
,
err
}
func
GetNodesDetail
(
projectName
,
pipelineName
,
runId
string
,
req
*
http
.
Request
)
([]
NodesDetail
,
error
)
{
getNodesUrl
:=
fmt
.
Sprintf
(
jenkins
.
Server
+
GetPipeRunNodesUrl
+
req
.
URL
.
RawQuery
,
projectName
,
pipelineName
,
runId
)
log
.
Infof
(
"getNodesUrl: "
+
getNodesUrl
)
var
wg
sync
.
WaitGroup
var
nodesDetails
[]
NodesDetail
stepChan
:=
make
(
chan
*
NodesStepsIndex
,
channelMaxCapacity
)
respNodes
,
err
:=
GetPipelineRunNodes
(
projectName
,
pipelineName
,
runId
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
err
=
json
.
Unmarshal
(
respNodes
,
&
nodesDetails
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
nil
,
err
}
// get all steps in nodes.
for
i
,
v
:=
range
nodesDetails
{
wg
.
Add
(
1
)
go
func
(
nodeId
string
,
index
int
)
{
var
steps
[]
NodeSteps
respSteps
,
err
:=
GetNodeSteps
(
projectName
,
pipelineName
,
runId
,
nodeId
,
req
)
if
err
!=
nil
{
log
.
Error
(
err
)
return
}
err
=
json
.
Unmarshal
(
respSteps
,
&
steps
)
stepChan
<-
&
NodesStepsIndex
{
index
,
steps
}
wg
.
Done
()
}(
v
.
ID
,
i
)
}
wg
.
Wait
()
close
(
stepChan
)
for
oneNodeSteps
:=
range
stepChan
{
if
oneNodeSteps
!=
nil
{
nodesDetails
[
oneNodeSteps
.
Id
]
.
Steps
=
append
(
nodesDetails
[
oneNodeSteps
.
Id
]
.
Steps
,
oneNodeSteps
.
Steps
...
)
}
}
return
nodesDetails
,
err
}
// create jenkins request
func
sendJenkinsRequest
(
baseUrl
string
,
req
*
http
.
Request
)
([]
byte
,
error
)
{
newReqUrl
,
err
:=
url
.
Parse
(
baseUrl
)
...
...
pkg/models/devops/json.go
浏览文件 @
0e50a93e
...
...
@@ -946,7 +946,7 @@ type BranchPipeline struct {
}
`json:"branch,omitempty"`
}
// GetPipeRunNodes
// GetPipe
line
RunNodes
type
PipelineRunNodes
struct
{
Class
string
`json:"_class,omitempty"`
Links
struct
{
...
...
@@ -1056,3 +1056,45 @@ type ResJson struct {
}
`json:"json,omitempty"`
}
`json:"data,omitempty"`
}
type
NodesDetail
struct
{
Class
string
`json:"_class,omitempty"`
Links
struct
{
Self
struct
{
Class
string
`json:"_class,omitempty"`
Href
string
`json:"href,omitempty"`
}
`json:"self,omitempty"`
Actions
struct
{
Class
string
`json:"_class,omitempty"`
Href
string
`json:"href,omitempty"`
}
`json:"actions,omitempty"`
Steps
struct
{
Class
string
`json:"_class,omitempty"`
Href
string
`json:"href,omitempty"`
}
`json:"steps,omitempty"`
}
`json:"_links,omitempty"`
Actions
[]
interface
{}
`json:"actions,omitempty"`
DisplayDescription
interface
{}
`json:"displayDescription,omitempty"`
DisplayName
string
`json:"displayName,omitempty"`
DurationInMillis
int
`json:"durationInMillis,omitempty"`
ID
string
`json:"id,omitempty"`
Input
interface
{}
`json:"input,omitempty"`
Result
string
`json:"result,omitempty"`
StartTime
string
`json:"startTime,omitempty"`
State
string
`json:"state,omitempty"`
Type
string
`json:"type,omitempty"`
CauseOfBlockage
interface
{}
`json:"causeOfBlockage,omitempty"`
Edges
[]
struct
{
Class
string
`json:"_class,omitempty"`
ID
string
`json:"id,omitempty"`
Type
string
`json:"type,omitempty"`
}
`json:"edges,omitempty"`
FirstParent
interface
{}
`json:"firstParent,omitempty"`
Restartable
bool
`json:"restartable,omitempty"`
Steps
[]
NodeSteps
`json:"steps,omitempty"`
}
type
NodesStepsIndex
struct
{
Id
int
`json:"id,omitempty"`
Steps
[]
NodeSteps
`json:"steps,omitempty"`
}
pkg/models/devops/urlconfig.go
浏览文件 @
0e50a93e
...
...
@@ -19,32 +19,40 @@ package devops
// Some apis for Jenkins.
const
(
GetPipeBranchUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/?"
GetBranchPipeUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/"
GetPipelineUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/"
SearchPipelineUrl
=
"/blue/rest/search/?"
SearchPipelineRunUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/?"
RunPipelineUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/"
GetPipelineRunUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/"
GetPipeBranchRunUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/"
SearchPipelineRunUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/?"
GetBranchPipeRunNodesUrl
=
"/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/?"
GetPipeRunNodesUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/?"
GetBranchRunLogUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/log/?"
GetRunLogUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/log/?"
GetBranchStepLogUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/%s/log/?"
GetStepLogUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/%s/steps/%s/log/?"
StopBranchPipelineUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/stop/?"
StopPipelineUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/runs/%s/stop/?"
ReplayBranchPipelineUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/replay/"
ReplayPipelineUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/runs/%s/replay/"
GetBranchArtifactsUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/artifacts/?"
GetArtifactsUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/artifacts/?"
GetBranchStepsStatusUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?"
GetStepsStatusUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/%s/steps/?"
CheckBranchPipelineUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%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/%s/branches/%s/runs/%s/nodes/%s/steps/?"
GetNodeStepsUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/%s/steps/?"
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/?"
StopPipelineUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/stop/?"
ReplayPipelineUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/replay/"
GetRunLogUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/log/?"
GetArtifactsUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/artifacts/?"
GetPipeBranchUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/?"
GetConsoleLogUrl
=
"/job/%s/job/%s/indexing/consoleText"
ScanBranchUrl
=
"/job/%s/job/%s/build?"
RunPipelineUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/"
GetStepsStatusUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?"
CheckPipelineUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/nodes/%s/steps/%s/"
GetCrumbUrl
=
"/crumbIssuer/api/json/"
CheckScriptCompileUrl
=
"/job/init-job/descriptorByName/org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition/checkScriptCompile"
CheckCronUrl
=
"/job/init-job/descriptorByName/hudson.triggers.TimerTrigger/checkSpec?"
GetPipelineRunUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/"
GetBranchPipeUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/"
GetPipeRunNodesUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/?"
GetNodeStepsUrl
=
"/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?"
ToJenkinsfileUrl
=
"/pipeline-model-converter/toJenkinsfile"
ToJsonUrl
=
"/pipeline-model-converter/toJson"
GetNotifyCommitUrl
=
"/git/notifyCommit/?"
...
...
pkg/simple/client/admin_jenkins/jenkins.go
浏览文件 @
0e50a93e
...
...
@@ -21,7 +21,7 @@ import (
)
var
(
jenkins
ClientOnce
sync
.
Once
jenkins
InitMutex
sync
.
Mutex
jenkinsClient
*
gojenkins
.
Jenkins
jenkinsAdminAddress
string
jenkinsAdminUsername
string
...
...
@@ -41,35 +41,36 @@ func init() {
}
func
Client
()
*
gojenkins
.
Jenkins
{
jenkinsClientOnce
.
Do
(
func
()
{
jenkins
:=
gojenkins
.
CreateJenkins
(
nil
,
jenkinsAdminAddress
,
jenkinsMaxConn
,
jenkinsAdminUsername
,
jenkinsAdminPassword
)
jenkins
,
err
:=
jenkins
.
Init
()
if
err
!=
nil
{
glog
.
Error
(
"failed to connect jenkins"
)
return
}
jenkinsClient
=
jenkins
globalRole
,
err
:=
jenkins
.
GetGlobalRole
(
JenkinsAllUserRoleName
)
if
err
!=
nil
{
glog
.
Error
(
"failed to get jenkins role"
)
}
if
globalRole
==
nil
{
_
,
err
:=
jenkins
.
AddGlobalRole
(
JenkinsAllUserRoleName
,
gojenkins
.
GlobalPermissionIds
{
GlobalRead
:
true
,
if
jenkinsClient
==
nil
{
jenkinsInitMutex
.
Lock
()
defer
jenkinsInitMutex
.
Unlock
()
if
jenkinsClient
==
nil
{
jenkins
:=
gojenkins
.
CreateJenkins
(
nil
,
jenkinsAdminAddress
,
jenkinsMaxConn
,
jenkinsAdminUsername
,
jenkinsAdminPassword
)
jenkins
,
err
:=
jenkins
.
Init
()
if
err
!=
nil
{
glog
.
Errorf
(
"failed to connect jenkins, %+v"
,
err
)
}
globalRole
,
err
:=
jenkins
.
GetGlobalRole
(
JenkinsAllUserRoleName
)
if
err
!=
nil
{
glog
.
Errorf
(
"failed to get jenkins role, %+v"
,
err
)
}
if
globalRole
==
nil
{
_
,
err
:=
jenkins
.
AddGlobalRole
(
JenkinsAllUserRoleName
,
gojenkins
.
GlobalPermissionIds
{
GlobalRead
:
true
,
},
true
)
if
err
!=
nil
{
glog
.
Errorf
(
"failed to create jenkins global role, %+v"
,
err
)
}
}
_
,
err
=
jenkins
.
AddProjectRole
(
JenkinsAllUserRoleName
,
"
\\
n
\\
s*
\\
r"
,
gojenkins
.
ProjectPermissionIds
{
SCMTag
:
true
,
},
true
)
if
err
!=
nil
{
glog
.
Error
(
"failed to create jenkins global role"
)
return
glog
.
Errorf
(
"failed to create jenkins project role, %+v"
,
err
)
}
jenkinsClient
=
jenkins
}
_
,
err
=
jenkins
.
AddProjectRole
(
JenkinsAllUserRoleName
,
"
\\
n
\\
s*
\\
r"
,
gojenkins
.
ProjectPermissionIds
{
SCMTag
:
true
,
},
true
)
if
err
!=
nil
{
glog
.
Error
(
"failed to create jenkins project role"
)
return
}
})
}
return
jenkinsClient
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录