2017-07-07 154 views
1

Changelog Mail output我试图通过一个邮件获取GitHub更改日志更改,当通过Jenkins进行构建时。Jenkins更新日志

我有下面的代码,这是给我的提交信息,但不是作者信息。我将如何获取提交的作者信息?我在“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:"[email protected]", 
    subject:"${env.JOB_NAME}(${env.BUILD_NUMBER}) completed", 
    mimeType:'text/html', 
    body:"${body}") 
} 

Stage('Notification'){ 
    echo "***** Send Email Notification *****" 
    sendEmail()  
} 

请让我知道,谢谢!

回答

0

这个完整的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:"[email protected]", 
    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>