2017-07-07 149 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>