首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jenkins Changelog

Jenkins Changelog
EN

Stack Overflow用户
提问于 2017-07-08 00:21:12
回答 1查看 292关注 0票数 1

当通过Jenkins进行构建时,我正在尝试通过邮件获取GitHub更改的日志。

我有下面的代码,它给我的是提交消息,而不是作者信息。我如何获取提交的作者信息?我在"getChangeString函数“中遗漏了什么吗?

代码语言:javascript
复制
@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()    
}

请让我知道,谢谢!

EN

回答 1

Stack Overflow用户

发布于 2017-07-08 10:02:03

这个完整的Jenkinsfile为我打印了作者的全名。我不认为有任何与作者相关的变化。我只需要调整几个东西就能让它运行。

代码语言:javascript
复制
@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()
      }
    }
  }
}

所以..。

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44975573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档