Jenkins Changelog

时间:2017-07-07 16:21:12

标签: git jenkins

Changelog Mail output当我通过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()    
}

请告诉我,谢谢!

1 个答案:

答案 0 :(得分: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:"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>