Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
devops-dev
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
demo
devops-dev
Commits
d008d355
Commit
d008d355
authored
Sep 27, 2019
by
梦良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交
parent
b5373929
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
45 deletions
+34
-45
app.conf
conf/app.conf
+3
-2
credential.go
controllers/credential.go
+0
-0
job.go
controllers/job.go
+28
-36
credential.go
dto/credential.go
+3
-7
No files found.
conf/app.conf
View file @
d008d355
...
...
@@ -6,4 +6,5 @@ copyrequestbody = true
EnableDocs
=
true
sqlconn
=
nameSpace
=
paas
configPath
= /
etc
/
kubeconfig
/
config
\ No newline at end of file
configPath
= /
etc
/
kubeconfig
/
config
defaultCredentialName
=
k2admin
\ No newline at end of file
controllers/credential.go
View file @
d008d355
This diff is collapsed.
Click to expand it.
controllers/job.go
View file @
d008d355
...
...
@@ -82,32 +82,31 @@ func (c *JobController) GetJobList() {
getAllJobUrl
:=
BaseURL
+
"/blue/rest/organizations/jenkins/pipelines/"
req
,
_
:=
http
.
NewRequest
(
"GET"
,
getAllJobUrl
,
nil
)
req
.
SetBasicAuth
(
"admin"
,
"K2pass!"
)
getAllJobRes
,
err
:=
httpClient
.
Do
(
req
)
if
err
!=
nil
{
errorLogger
.
Println
(
err
)
//if loginRes.StatusCode == http.StatusFound{
// infoLogger.Println(loginRes.Location())
//}
errorLogger
.
Println
(
"调用获取所有job接口失败:"
,
err
.
Error
())
errorResponseDto
.
Message
=
"获取所有job失败"
c
.
Data
[
"json"
]
=
errorResponseDto
c
.
ServeJSON
()
return
}
infoLogger
.
Println
(
getAllJobRes
)
getAllJobResByte
,
err
:=
ioutil
.
ReadAll
(
getAllJobRes
.
Body
)
if
err
!=
nil
{
errorLogger
.
Printf
(
"解析调用登录接口返回参数失败:%s"
,
err
.
Error
())
//errorResponseDto.Message = utils.GetI18nLang(lang,
// "getUserAllNameSpaces_parseCallInterfaceToGetUserAllNameSpacesResultFail")
//c.Data["json"] = errorResponseDto
//c.ServeJSON()
//return
errorLogger
.
Printf
(
"解析调用获取所有job接口返回参数失败:%s"
,
err
.
Error
())
errorResponseDto
.
Message
=
"解析调用获取所有job接口返回参数失败"
c
.
Data
[
"json"
]
=
errorResponseDto
c
.
ServeJSON
()
return
}
//infoLogger.Printf("调用登录接口返回值:%s", string(reqByte))
var
resMap
[]
map
[
string
]
interface
{}
if
err
:=
json
.
Unmarshal
(
getAllJobResByte
,
&
resMap
);
err
!=
nil
{
errorLogger
.
Println
(
"解析获取所有job接口返回数据失败:"
,
err
.
Error
())
errorResponseDto
.
Message
=
"解析获取所有job接口返回数据失败"
c
.
Data
[
"json"
]
=
errorResponseDto
c
.
ServeJSON
()
return
}
totalRecords
:=
len
(
resMap
)
...
...
@@ -170,13 +169,10 @@ func (c *JobController) GetJobList() {
infoLogger
.
Println
(
"job lastBuildUserName:"
,
lastBuildUserName
)
endTime
:=
latestRunMap
[
"endTime"
]
.
(
string
)
infoLogger
.
Println
(
"job endTime:"
,
endTime
)
endTimeStr
=
utils
.
ParseDate
(
endTime
,
false
)
infoLogger
.
Println
(
"job endTime:"
,
endTime
,
" "
,
endTimeStr
)
durationInMillis
:=
int64
(
latestRunMap
[
"durationInMillis"
]
.
(
float64
))
durationInMillisTimeStr
,
_
=
utils
.
ParseMilliSecondsDateToString
(
lang
,
durationInMillis
)
infoLogger
.
Println
(
"job durationInMillis:"
,
durationInMillis
,
" "
,
durationInMillisTimeStr
)
}
...
...
@@ -644,14 +640,14 @@ func (c *JobController) CreatePipelineJob() {
//执行创建job
execCreatePipelineJobRes
:=
ExecCreatePipelineJob
(
requestDto
.
JobName
)
if
execCreatePipelineJobRes
.
Status
==
300
{
errorLogger
.
Printf
(
"执行创建
%s job
失败:%s"
,
jobName
,
execCreatePipelineJobRes
.
Message
)
errorLogger
.
Printf
(
"执行创建
job:%s
失败:%s"
,
jobName
,
execCreatePipelineJobRes
.
Message
)
responseDto
.
Message
=
execCreatePipelineJobRes
.
Message
c
.
Data
[
"json"
]
=
responseDto
c
.
ServeJSON
()
return
}
infoLogger
.
Printf
(
"执行配置
%s job
"
,
jobName
)
infoLogger
.
Printf
(
"执行配置
job:%s
"
,
jobName
)
//执行配置job
...
...
@@ -696,17 +692,16 @@ func ExecCreatePipelineJob(jobName string) dto.BaseResponseDto {
url
.
QueryEscape
(
string
(
paramsByte
))
infoLogger
.
Println
(
paramsStr
)
req
,
_
:=
http
.
NewRequest
(
"POST"
,
createUrl
+
"?"
+
paramsStr
,
nil
)
req
.
SetBasicAuth
(
"admin"
,
"K2pass!"
)
req
.
Header
.
Set
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
createRes
,
err
:=
httpClient
.
Do
(
req
)
if
err
!=
nil
{
errorLogger
.
Printf
(
"执行创建
%s job
失败:%s"
,
jobName
,
err
.
Error
())
errorLogger
.
Printf
(
"执行创建
job:%s
失败:%s"
,
jobName
,
err
.
Error
())
responseDto
.
Message
=
"执行创建job失败"
return
responseDto
}
infoLogger
.
Printf
(
"执行创建
%s job
返回结果:%v"
,
jobName
,
createRes
)
infoLogger
.
Printf
(
"执行创建
job:%s
返回结果:%v"
,
jobName
,
createRes
)
errorRes
:=
createRes
.
Header
.
Get
(
"X-Error"
)
infoLogger
.
Printf
(
"返回错误信息:%s"
,
errorRes
)
if
errorRes
!=
""
&&
strings
.
Contains
(
errorRes
,
"A job already exists with the name "
+
jobName
)
{
...
...
@@ -717,7 +712,7 @@ func ExecCreatePipelineJob(jobName string) dto.BaseResponseDto {
responseDto
.
Message
=
"执行创建job失败"
return
responseDto
}
infoLogger
.
Printf
(
"执行创建
%s job
成功"
,
jobName
)
infoLogger
.
Printf
(
"执行创建
job:%s
成功"
,
jobName
)
responseDto
.
Status
=
200
responseDto
.
Message
=
"成功"
...
...
@@ -744,7 +739,7 @@ func (c *JobController) StartRunPipelineJob() {
c
.
ServeJSON
()
return
}
infoLogger
.
Println
(
"启动
构建
job请求参数: "
,
requestDto
)
infoLogger
.
Println
(
"启动
运行
job请求参数: "
,
requestDto
)
jobName
:=
requestDto
.
JobName
if
strings
.
TrimSpace
(
jobName
)
==
""
{
errorLogger
.
Println
(
"job名称不能为空"
)
...
...
@@ -765,22 +760,21 @@ func (c *JobController) StartRunPipelineJob() {
}
req
,
_
:=
http
.
NewRequest
(
"POST"
,
buildUrl
,
nil
)
req
.
SetBasicAuth
(
"admin"
,
"K2pass!"
)
req
.
Header
.
Set
(
"Content-Type"
,
"application/json;charset=utf-8"
)
startRes
,
err
:=
httpClient
.
Do
(
req
)
if
err
!=
nil
{
errorLogger
.
Println
(
err
)
errorLogger
.
Printf
(
"启动
构建%s job
失败:%s"
,
jobName
,
err
.
Error
())
responseDto
.
Message
=
"启动
构建
job失败"
errorLogger
.
Printf
(
"启动
运行job:%s
失败:%s"
,
jobName
,
err
.
Error
())
responseDto
.
Message
=
"启动
运行
job失败"
c
.
Data
[
"json"
]
=
responseDto
c
.
ServeJSON
()
return
}
infoLogger
.
Printf
(
"启动
构建%sjob
返回状态码:%s"
,
jobName
,
startRes
.
Status
)
infoLogger
.
Printf
(
"启动
运行job:%s
返回状态码:%s"
,
jobName
,
startRes
.
Status
)
if
startRes
.
StatusCode
!=
http
.
StatusFound
{
responseDto
.
Message
=
"启动
构建
job失败"
responseDto
.
Message
=
"启动
运行
job失败"
if
startRes
.
StatusCode
==
http
.
StatusNotFound
{
responseDto
.
Message
=
"job不存在"
}
...
...
@@ -788,7 +782,7 @@ func (c *JobController) StartRunPipelineJob() {
c
.
ServeJSON
()
return
}
infoLogger
.
Printf
(
"启动
构建%s job
成功"
,
jobName
)
infoLogger
.
Printf
(
"启动
运行job:%s
成功"
,
jobName
)
responseDto
.
Status
=
200
responseDto
.
Message
=
"成功"
...
...
@@ -840,19 +834,17 @@ func (c *JobController) DeletePipelineJob() {
}
req
,
_
:=
http
.
NewRequest
(
"POST"
,
buildUrl
,
nil
)
req
.
SetBasicAuth
(
"admin"
,
"K2pass!"
)
req
.
Header
.
Set
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
deleteRes
,
err
:=
httpClient
.
Do
(
req
)
if
err
!=
nil
{
errorLogger
.
Println
(
err
)
errorLogger
.
Printf
(
"执行删除%s job失败:%s"
,
jobName
,
err
.
Error
())
errorLogger
.
Printf
(
"执行删除job:%s失败:%s"
,
jobName
,
err
.
Error
())
responseDto
.
Message
=
"执行删除job失败"
c
.
Data
[
"json"
]
=
responseDto
c
.
ServeJSON
()
return
}
infoLogger
.
Printf
(
"执行删除
%s job
返回状态码:%s"
,
jobName
,
deleteRes
.
Status
)
infoLogger
.
Printf
(
"执行删除
job:%s
返回状态码:%s"
,
jobName
,
deleteRes
.
Status
)
if
deleteRes
.
StatusCode
!=
http
.
StatusFound
{
responseDto
.
Message
=
"执行删除job失败"
if
deleteRes
.
StatusCode
==
http
.
StatusNotFound
{
...
...
@@ -862,7 +854,7 @@ func (c *JobController) DeletePipelineJob() {
c
.
ServeJSON
()
return
}
infoLogger
.
Printf
(
"执行删除
%s job
成功"
,
jobName
)
infoLogger
.
Printf
(
"执行删除
job:%s
成功"
,
jobName
)
responseDto
.
Status
=
200
responseDto
.
Message
=
"成功"
...
...
dto/credential.go
View file @
d008d355
package
dto
type
GetCredentialsResponseDto
struct
{
JobName
string
`json:"jobName"`
//job 名称
LastStatus
string
`json:"lastStatus"`
//最近状态
LastBuildUserName
string
`json:"lastBuildUserName"`
//最近构建人名称
Description
string
`json:"description"`
//描述信息
LastUpdateTime
string
`json:"lastUpdateTime"`
//最近更新时间即最近job结束时间
DurationInMillis
string
`json:"durationInMillis"`
//上次持续时间
type
GetAllCredentialsResultResponseDto
struct
{
CredentialId
string
`json:"credentialId"`
//凭据id
CredentialName
string
`json:"credentialName"`
//凭据名称
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment