
当通过Jenkins进行构建时,我正在尝试通过邮件获取GitHub更改的日志。
我有下面的代码,它给我的是提交消息,而不是作者信息。我如何获取提交的作者信息?我在"getChangeString函数“中遗漏了什么吗?
@NonCPS
def getChangeString() {
MAX_MSG_LEN = 100
def changeString = ""
echo "Gathering SCM changes"
def changeLogSets = currentBuild.changeSets
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]
truncated_msg = entry.msg.take(MAX_MSG_LEN)
echo "******${entry.author}**********"
changeString += " <tr><td> ${truncated_msg} </td><td> [${entry.author}]
</td></tr>\n"
}
}
if (!changeString) {
changeString = " <tr><td> No changes </td><td> No changes </td></tr>"
}
return changeString
}
def sendEmail() {
String Changelog=getChangeString()
body 1, body 2, body 3 = some of my personal text
def body=body1+getChangeString()+body2+build_url+body3
mail(to:"xxxx@gmail.com",
subject:"${env.JOB_NAME}(${env.BUILD_NUMBER}) completed",
mimeType:'text/html',
body:"${body}")
}
Stage('Notification'){
echo "***** Send Email Notification *****"
sendEmail()
}请让我知道,谢谢!
发布于 2017-07-08 10:02:03
这个完整的Jenkinsfile为我打印了作者的全名。我不认为有任何与作者相关的变化。我只需要调整几个东西就能让它运行。
@NonCPS
def getChangeString() {
MAX_MSG_LEN = 100
def changeString = ""
echo "Gathering SCM changes"
def changeLogSets = currentBuild.changeSets
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]
truncated_msg = entry.msg.take(MAX_MSG_LEN)
echo "******${entry.author}**********"
changeString += " <tr><td> ${truncated_msg} </td><td> [${entry.author}]</td></tr>\n"
}
}
if (!changeString) {
changeString = " <tr><td> No changes </td><td> No changes </td></tr>"
}
return changeString
}
def sendEmail() {
def body=getChangeString()
mail(to:"hey@example.com",
subject:"${env.JOB_NAME}(${env.BUILD_NUMBER}) completed",
mimeType:'text/html',
body:"${body}")
}
pipeline {
agent { label 'docker' }
stages {
stage('notification') {
steps {
echo "***** Send Email Notification *****"
sendEmail()
}
}
}
}所以..。
<joke>if it still doesn't print the author for you, i think the most likely
explanation is that someone hacked your git hosting tool and replaced it with a
double with perfect fidelity except that it doesn't capture the author</joke>https://stackoverflow.com/questions/44975573
复制相似问题