Jenkins 子模块信息测试
This commit is contained in:
parent
221e312447
commit
ecde2b0e4a
@ -5,6 +5,54 @@
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurperClassic
|
||||
import com.cloudbees.groovy.cps.NonCPS
|
||||
|
||||
@NonCPS
|
||||
def getTriggerUser(buildCauses)
|
||||
{
|
||||
def triggerUser = "自动触发"
|
||||
if (buildCauses && buildCauses.size() > 0 && buildCauses[0].userName) {
|
||||
triggerUser = buildCauses[0].userName
|
||||
}
|
||||
return triggerUser
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
def getFailedStage(build)
|
||||
{
|
||||
def failedStage = ""
|
||||
if (build.currentResult == 'FAILURE') {
|
||||
def stages = build.rawBuild.getAction(org.jenkinsci.plugins.workflow.job.views.FlowGraphAction)?.getNodes()
|
||||
if (stages) {
|
||||
for (stage in stages) {
|
||||
if (stage.getError() != null) {
|
||||
failedStage = "\n- 失败阶段: ${stage.getDisplayName()}"
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return failedStage
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
def getMainRepoChangeString(changeLogSets)
|
||||
{
|
||||
def changeString = ""
|
||||
if (changeLogSets && changeLogSets.size() > 0) {
|
||||
changeString = "\n\n提交记录:\n"
|
||||
for (int i = 0; i < changeLogSets.size(); i++) {
|
||||
def entries = changeLogSets[i].items
|
||||
for (int j = 0; j < entries.length; j++) {
|
||||
def entry = entries[j]
|
||||
changeString += "- ${entry.commitId.take(7)} ${entry.msg} - ${entry.author}\n"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
changeString = "\n\n提交记录: 无变更"
|
||||
}
|
||||
return changeString
|
||||
}
|
||||
|
||||
def call(Map config)
|
||||
{
|
||||
@ -98,41 +146,13 @@ def call(Map config)
|
||||
{
|
||||
script {
|
||||
// 获取触发者
|
||||
def triggerUser = "自动触发"
|
||||
def buildCause = currentBuild.getBuildCauses()
|
||||
if (buildCause && buildCause.size() > 0 && buildCause[0].userName) {
|
||||
triggerUser = buildCause[0].userName
|
||||
}
|
||||
def triggerUser = getTriggerUser(currentBuild.getBuildCauses())
|
||||
|
||||
// 获取失败阶段(仅失败时)
|
||||
def failedStage = ""
|
||||
if (currentBuild.currentResult == 'FAILURE') {
|
||||
def stages = currentBuild.rawBuild.getAction(org.jenkinsci.plugins.workflow.job.views.FlowGraphAction)?.getNodes()
|
||||
if (stages) {
|
||||
for (stage in stages) {
|
||||
if (stage.getError() != null) {
|
||||
failedStage = "\n- 失败阶段: ${stage.getDisplayName()}"
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
def failedStage = getFailedStage(currentBuild)
|
||||
|
||||
// 收集提交记录
|
||||
def changeString = ""
|
||||
def changeLogSets = currentBuild.changeSets
|
||||
if (changeLogSets.size() > 0) {
|
||||
changeString = "\n\n提交记录:\n"
|
||||
for (int i = 0; i < changeLogSets.size(); i++) {
|
||||
def entries = changeLogSets[i].items
|
||||
for (int j = 0; j < entries.length; j++) {
|
||||
def entry = entries[j]
|
||||
changeString += "- ${entry.commitId.take(7)} ${entry.msg} - ${entry.author}\n"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
changeString = "\n\n提交记录: 无变更"
|
||||
}
|
||||
def changeString = getMainRepoChangeString(currentBuild.changeSets)
|
||||
|
||||
// 收集子模块提交记录(与上一次构建对比)
|
||||
def submoduleChangeString = ""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user