Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qa-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
qa-api
Commits
0a535560
Commit
0a535560
authored
Nov 25, 2019
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
branchName 提取
parent
ebf63fac
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
17 deletions
+17
-17
pipeline.js
app/controller/pipeline.js
+7
-8
proconfig.js
app/controller/proconfig.js
+1
-1
sonar.js
app/controller/sonar.js
+6
-5
sonarCheck.js
app/jobs/sonarCheck.js
+2
-2
dingTalk.js
app/utils/dingTalk.js
+1
-1
No files found.
app/controller/pipeline.js
View file @
0a535560
...
@@ -76,8 +76,7 @@ const webhooks = async function (ctx) {
...
@@ -76,8 +76,7 @@ const webhooks = async function (ctx) {
logger
.
info
(
'
webhooks
'
,
req
)
logger
.
info
(
'
webhooks
'
,
req
)
const
projectName
=
req
.
repository
.
name
const
projectName
=
req
.
repository
.
name
const
arr
=
req
.
ref
.
split
(
'
/
'
)
const
branchName
=
req
.
ref
.
replace
(
'
refs/heads/
'
,
''
)
const
branchName
=
arr
[
arr
.
length
-
1
]
logger
.
info
(
`收到webhooks->>>项目名:
${
projectName
}
分支名:
${
branchName
}
`
)
logger
.
info
(
`收到webhooks->>>项目名:
${
projectName
}
分支名:
${
branchName
}
`
)
// user_add_to_team project_create之类的操作
// user_add_to_team project_create之类的操作
...
@@ -126,13 +125,13 @@ const webhooks = async function (ctx) {
...
@@ -126,13 +125,13 @@ const webhooks = async function (ctx) {
}
}
}
}
}
}
if
(
gitObject
==
null
||
gitObject
===
undefined
)
{
if
(
gitObject
)
{
logger
.
info
(
`未查询到订阅信息->>>项目名:
${
projectName
}
分支名:
${
branchName
}
,不执行pipeline jenkins`
)
}
else
{
logger
.
info
(
'
webhooks 触发 pipeline jenkins build
'
,
projectName
,
branchName
,
req
.
checkout_sha
)
logger
.
info
(
'
webhooks 触发 pipeline jenkins build
'
,
projectName
,
branchName
,
req
.
checkout_sha
)
pipelineJenkinsBuild
({
pipelineJenkinsBuild
({
projectName
,
branchName
,
type
:
gitObject
.
type
,
gitUser
,
commitMes
,
timestamp
,
projectName
,
branchName
,
type
:
gitObject
.
type
,
gitUser
,
commitMes
,
timestamp
,
})
})
}
else
{
logger
.
info
(
`未查询到订阅信息->>>项目名:
${
projectName
}
分支名:
${
branchName
}
,不执行pipeline jenkins`
)
}
}
ctx
.
body
=
ctx
.
ok
(
'
success
'
)
ctx
.
body
=
ctx
.
ok
(
'
success
'
)
...
@@ -210,7 +209,7 @@ const sendSuccessDing = async (data, pipeLineData, pushData) => {
...
@@ -210,7 +209,7 @@ const sendSuccessDing = async (data, pipeLineData, pushData) => {
+
`> 触发时间 :
${
pushData
.
gitEventTime
}
\n\n`
+
`> 触发时间 :
${
pushData
.
gitEventTime
}
\n\n`
+
`[查看详情](
${
data
.
absoluteUrl
}
console)`
+
`[查看详情](
${
data
.
absoluteUrl
}
console)`
const
address
=
pipeLineData
.
noticeAddress
||
data
.
dingRobotAddr
const
address
=
pipeLineData
.
noticeAddress
||
data
.
dingRobotAddr
await
dingTalk
(
title
,
text
,
address
)
await
dingTalk
(
`
${
pushData
.
projectName
}${
title
}
`
,
text
,
address
)
}
}
const
sendSonarFailDing
=
async
(
data
,
pipeLineData
)
=>
{
const
sendSonarFailDing
=
async
(
data
,
pipeLineData
)
=>
{
...
@@ -224,7 +223,7 @@ const sendSonarFailDing = async (data, pipeLineData) => {
...
@@ -224,7 +223,7 @@ const sendSonarFailDing = async (data, pipeLineData) => {
+
`[Jenkins详情](
${
data
.
absoluteUrl
}
console)\n\n`
+
`[Jenkins详情](
${
data
.
absoluteUrl
}
console)\n\n`
+
`[Sonar详情](
${
config
.
sonarHost
}
/project/activity?id=
${
sonarJob
.
projectName
}
&&selected_date=
${
sonarJob
.
analysisDate
}
)`
+
`[Sonar详情](
${
config
.
sonarHost
}
/project/activity?id=
${
sonarJob
.
projectName
}
&&selected_date=
${
sonarJob
.
analysisDate
}
)`
const
address
=
pipeLineData
.
noticeAddress
||
data
.
dingRobotAddr
const
address
=
pipeLineData
.
noticeAddress
||
data
.
dingRobotAddr
await
dingTalk
(
title
,
text
,
address
)
await
dingTalk
(
`
${
sonarJob
.
projectName
}${
title
}
`
,
text
,
address
)
}
}
const
sendExceptionDing
=
async
(
data
,
pipeLineData
)
=>
{
const
sendExceptionDing
=
async
(
data
,
pipeLineData
)
=>
{
...
@@ -234,7 +233,7 @@ const sendExceptionDing = async (data, pipeLineData) => {
...
@@ -234,7 +233,7 @@ const sendExceptionDing = async (data, pipeLineData) => {
+
`> 触发时间 :
${
moment
().
format
(
'
YYYY-MM-DD HH:mm:ss
'
)}
\n\n`
+
`> 触发时间 :
${
moment
().
format
(
'
YYYY-MM-DD HH:mm:ss
'
)}
\n\n`
+
`[Jenkins详情](
${
data
.
absoluteUrl
}
console)\n\n`
+
`[Jenkins详情](
${
data
.
absoluteUrl
}
console)\n\n`
const
address
=
pipeLineData
.
noticeAddress
||
data
.
dingRobotAddr
const
address
=
pipeLineData
.
noticeAddress
||
data
.
dingRobotAddr
await
dingTalk
(
title
,
text
,
address
)
await
dingTalk
(
`
${
data
.
projectName
}${
title
}
`
,
text
,
address
)
}
}
const
callback
=
async
(
ctx
)
=>
{
const
callback
=
async
(
ctx
)
=>
{
...
...
app/controller/proconfig.js
View file @
0a535560
...
@@ -55,7 +55,7 @@ const save = async function (ctx) {
...
@@ -55,7 +55,7 @@ const save = async function (ctx) {
return
return
}
}
if
(
~
data
.
host_name
.
indexOf
(
'
://
'
))
{
if
(
data
.
host_name
&&
~
data
.
host_name
.
indexOf
(
'
://
'
))
{
ctx
.
body
=
ctx
.
fail
(
'
线上域名不要有 http://
'
)
ctx
.
body
=
ctx
.
fail
(
'
线上域名不要有 http://
'
)
return
return
}
}
...
...
app/controller/sonar.js
View file @
0a535560
...
@@ -22,7 +22,7 @@ const sendFailDing = async (data, item, executionTimeMs) => {
...
@@ -22,7 +22,7 @@ const sendFailDing = async (data, item, executionTimeMs) => {
// + `[查看详情](${config.sonarHost}/dashboard?id=${data.project})`
// + `[查看详情](${config.sonarHost}/dashboard?id=${data.project})`
+
`[查看详情](
${
config
.
sonarHost
}
/project/activity?id=
${
data
.
project
}
&&selected_date=
${
item
.
analysisDate
}
)`
+
`[查看详情](
${
config
.
sonarHost
}
/project/activity?id=
${
data
.
project
}
&&selected_date=
${
item
.
analysisDate
}
)`
const
address
=
data
.
dingRobotAddr
const
address
=
data
.
dingRobotAddr
await
dingTalk
(
title
,
text
,
address
)
await
dingTalk
(
`
${
data
.
project
}${
title
}
`
,
text
,
address
)
}
}
const
sendExceptionDing
=
async
(
data
)
=>
{
const
sendExceptionDing
=
async
(
data
)
=>
{
...
@@ -32,7 +32,7 @@ const sendExceptionDing = async (data) => {
...
@@ -32,7 +32,7 @@ const sendExceptionDing = async (data) => {
+
`> 分支名称 :
${
data
.
branch
}
\n\n`
+
`> 分支名称 :
${
data
.
branch
}
\n\n`
+
`[查看详情](
${
data
.
absoluteUrl
}
console)`
+
`[查看详情](
${
data
.
absoluteUrl
}
console)`
const
address
=
data
.
dingRobotAddr
||
config
.
snorDingRobotAddr
const
address
=
data
.
dingRobotAddr
||
config
.
snorDingRobotAddr
await
dingTalk
(
title
,
text
,
address
)
await
dingTalk
(
`
${
data
.
project
}${
title
}
`
,
text
,
address
)
}
}
const
sendExistDing
=
async
(
data
,
dingRobotAddr
)
=>
{
const
sendExistDing
=
async
(
data
,
dingRobotAddr
)
=>
{
...
@@ -44,7 +44,7 @@ const sendExistDing = async (data, dingRobotAddr) => {
...
@@ -44,7 +44,7 @@ const sendExistDing = async (data, dingRobotAddr) => {
+
`> 扫描分析日期 :
${
data
.
analysisDate
}
\n\n`
+
`> 扫描分析日期 :
${
data
.
analysisDate
}
\n\n`
+
`[查看详情](
${
config
.
sonarHost
}
/project/activity?id=
${
data
.
projectName
}
&&selected_date=
${
data
.
analysisDate
}
)`
+
`[查看详情](
${
config
.
sonarHost
}
/project/activity?id=
${
data
.
projectName
}
&&selected_date=
${
data
.
analysisDate
}
)`
const
address
=
dingRobotAddr
||
config
.
snorDingRobotAddr
const
address
=
dingRobotAddr
||
config
.
snorDingRobotAddr
await
dingTalk
(
title
,
text
,
address
)
await
dingTalk
(
`
${
data
.
projectName
}${
title
}
`
,
text
,
address
)
}
}
const
callback
=
async
(
ctx
)
=>
{
const
callback
=
async
(
ctx
)
=>
{
...
@@ -52,7 +52,8 @@ const callback = async (ctx) => {
...
@@ -52,7 +52,8 @@ const callback = async (ctx) => {
logger
.
info
(
'
sonar callback info
'
,
data
)
logger
.
info
(
'
sonar callback info
'
,
data
)
if
(
data
.
sonarJob
)
{
if
(
data
.
sonarJob
)
{
logger
.
info
(
data
.
sonarJob
.
projectName
,
data
.
sonarJob
.
branchName
,
data
.
sonarJob
.
branchHash
,
'
GITHASH 曾经 扫描过
'
)
logger
.
info
(
data
.
sonarJob
.
projectName
,
data
.
sonarJob
.
branchName
,
data
.
sonarJob
.
branchHash
,
'
GITHASH 曾经 扫描过,扫描结果:
'
,
data
.
sonarJob
)
if
(
data
.
sonarJob
.
sonarResult
!==
'
OK
'
&&
data
.
dingRobotAddr
)
{
if
(
data
.
sonarJob
.
sonarResult
!==
'
OK
'
&&
data
.
dingRobotAddr
)
{
sendExistDing
(
data
.
sonarJob
,
data
.
dingRobotAddr
)
sendExistDing
(
data
.
sonarJob
,
data
.
dingRobotAddr
)
}
}
...
@@ -110,7 +111,7 @@ const callback = async (ctx) => {
...
@@ -110,7 +111,7 @@ const callback = async (ctx) => {
await
SonarJob
.
saveSonarJob
(
saveData
)
await
SonarJob
.
saveSonarJob
(
saveData
)
}
}
}
}
ctx
.
body
=
ctx
.
ok
()
ctx
.
body
=
ctx
.
ok
(
saveData
)
}
}
const
getSonarJob
=
async
(
ctx
)
=>
{
const
getSonarJob
=
async
(
ctx
)
=>
{
...
...
app/jobs/sonarCheck.js
View file @
0a535560
...
@@ -23,12 +23,12 @@ const sonarCheck = async () => {
...
@@ -23,12 +23,12 @@ const sonarCheck = async () => {
}
}
jenkinsService
.
build_with_params
(
'
tke-sonar
'
,
data
)
jenkinsService
.
build_with_params
(
'
tke-sonar
'
,
data
)
logger
.
info
(
'
daily sonarCheck
'
,
data
)
logger
.
info
(
'
daily sonarCheck
'
,
data
)
await
sleep
(
30
*
1000
)
await
sleep
(
15
*
1000
)
}
}
logger
.
info
(
'
daily sonarCheck end
'
)
logger
.
info
(
'
daily sonarCheck end
'
)
}
}
module
.
exports
=
schedule
.
scheduleJob
(
'
0 22
* * *
'
,
async
()
=>
{
module
.
exports
=
schedule
.
scheduleJob
(
'
30 21
* * *
'
,
async
()
=>
{
try
{
try
{
await
sonarCheck
()
await
sonarCheck
()
}
catch
(
e
)
{
}
catch
(
e
)
{
...
...
app/utils/dingTalk.js
View file @
0a535560
...
@@ -18,6 +18,6 @@ module.exports = async (title, text, url) => {
...
@@ -18,6 +18,6 @@ module.exports = async (title, text, url) => {
},
},
body
:
JSON
.
stringify
(
dingData
),
body
:
JSON
.
stringify
(
dingData
),
})
})
logger
.
info
(
`发送
Sonar
dingtalk
${
JSON
.
stringify
(
dingData
)}
`
)
logger
.
info
(
`发送 dingtalk
${
JSON
.
stringify
(
dingData
)}
`
)
}
}
}
}
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