子模块日志查看
This commit is contained in:
parent
96af59913e
commit
b2d1a7a593
@ -3,6 +3,9 @@
|
||||
// Copyright Byway Studios Inc. All rights reserved
|
||||
//=================================================================
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurperClassic
|
||||
|
||||
def call(Map config)
|
||||
{
|
||||
pipeline
|
||||
@ -130,6 +133,88 @@ def call(Map config)
|
||||
} else {
|
||||
changeString = "\n\n提交记录: 无变更"
|
||||
}
|
||||
|
||||
// 收集子模块提交记录(与上一次构建对比)
|
||||
def submoduleChangeString = ""
|
||||
def submoduleStateFile = ".jenkins_submodule_state_dev.json"
|
||||
def previousSubmoduleStates = [:]
|
||||
def currentSubmoduleStates = [:]
|
||||
|
||||
if (fileExists(submoduleStateFile)) {
|
||||
try {
|
||||
previousSubmoduleStates = new JsonSlurperClassic().parseText(readFile(submoduleStateFile)) ?: [:]
|
||||
} catch (Exception ignored) {
|
||||
previousSubmoduleStates = [:]
|
||||
}
|
||||
}
|
||||
|
||||
if (fileExists('.git') && fileExists('.gitmodules')) {
|
||||
try {
|
||||
def submoduleStatusOutput = bat(
|
||||
returnStdout: true,
|
||||
script: '@echo off\r\ngit submodule status --recursive'
|
||||
).trim()
|
||||
|
||||
def submoduleLines = submoduleStatusOutput ? submoduleStatusOutput.readLines().findAll { it?.trim() } : []
|
||||
def submoduleSections = []
|
||||
|
||||
submoduleLines.each { rawLine ->
|
||||
def line = rawLine.replace('\r', '')
|
||||
def matcher = (line =~ /^(.)([0-9a-f]{40})\s+([^\(]+?)(?:\s+\((.+)\))?$/)
|
||||
if (!matcher.matches()) {
|
||||
return
|
||||
}
|
||||
|
||||
def submodulePath = matcher[0][3].trim()
|
||||
def currentSha = bat(
|
||||
returnStdout: true,
|
||||
script: "@echo off\r\ngit -C \"${submodulePath}\" rev-parse HEAD"
|
||||
).trim()
|
||||
def currentHeadMessage = bat(
|
||||
returnStdout: true,
|
||||
script: "@echo off\r\ngit -C \"${submodulePath}\" log -1 --pretty=format:\"%h %s - %an\""
|
||||
).trim()
|
||||
|
||||
currentSubmoduleStates[submodulePath] = [sha: currentSha]
|
||||
|
||||
def previousSha = previousSubmoduleStates[submodulePath]?.sha
|
||||
if (previousSha && previousSha != currentSha) {
|
||||
def commitLogs = ""
|
||||
try {
|
||||
commitLogs = bat(
|
||||
returnStdout: true,
|
||||
script: "@echo off\r\ngit -C \"${submodulePath}\" log --pretty=format:\"- %h %s - %an\" ${previousSha}..${currentSha}"
|
||||
).trim()
|
||||
} catch (Exception ignored) {
|
||||
commitLogs = "- ${currentHeadMessage}"
|
||||
}
|
||||
|
||||
if (!commitLogs) {
|
||||
commitLogs = "- ${currentHeadMessage}"
|
||||
}
|
||||
|
||||
submoduleSections << "- 子模块: ${submodulePath}\n${commitLogs}"
|
||||
} else if (!previousSha) {
|
||||
submoduleSections << "- 子模块: ${submodulePath}\n- 首次记录: ${currentHeadMessage}"
|
||||
}
|
||||
}
|
||||
|
||||
if (submoduleSections.size() > 0) {
|
||||
submoduleChangeString = "\n\n子模块提交记录:\n" + submoduleSections.join("\n")
|
||||
} else {
|
||||
submoduleChangeString = "\n\n子模块提交记录: 无变更"
|
||||
}
|
||||
|
||||
writeFile(
|
||||
file: submoduleStateFile,
|
||||
text: JsonOutput.prettyPrint(JsonOutput.toJson(currentSubmoduleStates))
|
||||
)
|
||||
} catch (Exception ignored) {
|
||||
submoduleChangeString = "\n\n子模块提交记录: 收集失败"
|
||||
}
|
||||
} else {
|
||||
submoduleChangeString = "\n\n子模块提交记录: 无子模块"
|
||||
}
|
||||
|
||||
dingtalk(
|
||||
robot:'dingtalk_unity_1',
|
||||
@ -145,7 +230,8 @@ def call(Map config)
|
||||
"- 耗时: ${currentBuild.durationString}${failedStage}",
|
||||
"\n链接:",
|
||||
"- [下载链接](${env.BUILD_URL})",
|
||||
changeString
|
||||
changeString,
|
||||
submoduleChangeString
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user