配置用户提交评论、添加issue等的邮件通知:

Gitlab邮件提醒方便跟踪项目进度,在这里介绍两种方式,一种是用系统的sendmail发送邮件,另一种是GMAIL的stmp来发送邮件

第一种 用系统的sendmail发送邮件

cd /home/gitlab/gitlab/

vi config/environments/production.rb

将这行 # config.action_mailer.delivery_method = :sendmail

改为    config.action_mailer.delivery_method = :sendmail

保存config/environments/production.rb

编辑config/gitlab.yml

vi config/gitlab.yml

对应修改一下配置

web:

host: gitlab123.com

port: 80

https: false

email:

from: notify@gitlab123.com

protocol: http

host: gitlab123.com

git_host:

host: gitlab123.com

编辑/etc/hosts

加入你的ip对应gitlab123.com

10.0.0.71    gitlab123.com

第二种 GMAIL的stmp来发送邮件

cd /home/gitlab/gitlab/

vi config/environments/production.rb

在# config.action_mailer.delivery_method = :sendmail下加入

config.action_mailer.delivery_method = :smtp

config.action_mailer.perform_deliveries = true

config.action_mailer.raise_delivery_errors = true

config.action_mailer.smtp_settings = {

:address              => "smtp.gmail.com",

:port                 => 587,

:domain               => 'gmail.com',

:user_name            => 'account@gmail.com',

:password             => 'password',

:authentication       =>  :plain,

:enable_starttls_auto => true

}

#配置好你的邮箱和密码

编辑config/gitlab.yml

vi config/gitlab.yml

对应修改一下配置

email:

from: account@gmail.com

protocol: http

配置源码push到版本库时的通知:

0、先安装msmtp,参考http://www.cnblogs.com/hanxianlong/p/3474429.html

1、进入到repositories中,如/opt/gitlab-6.3.0-0/apps/gitlab/repositories/imagesys5/test.git

cd /opt/gitlab-6.3.0-0/apps/gitlab/repositories/imagesys5/test.git

2、到项目的hooks目录中,新建一个名为post-receive的hook软链接,指向到/usr/share/doc/git-1.7.1/contrib/hooks/post-receive-email

  ln -s /usr/share/doc/git-1.7.1/contrib/hooks/post-receive-email hooks/post-receive

3、编辑项目的config文件

vim config

新增如下配置节:
[hooks]
mailinglist = "YOURMAIL1@MAILSERVER.COM,YOURMAIL2@MAILSERVER.COM"
emailprefix="[GIT]"

4、编辑项目的Description名称

vim description

修改内容为项目名称

5、修改/usr/share/doc/git-1.7.1/contrib/hooks/post-receive-email文件的send_mail函数(大约640行和642行),将/usr/sbin/sendmail替换为/usr/bin/msmtp

send_mail()
638 {
639 if [ -n "$envelopesender" ]; then
640 #/usr/sbin/sendmail -t -f "$envelopesender"
641 /usr/bin/msmtp -t -f "$envelopesender"
642 else
643 #/usr/sbin/sendmail -t
644 /usr/bin/msmtp -t
645 fi
646 }

##############################

Introduction

为Git repository 添加hook,每次commit 时发送一封diff email

Procedure

  1. 拷贝Git-core自带的post-receive-email Shell 脚本

    mv YOUR_REPO_PATH/hooks/post-receive YOUR_REPO_PATH/hooks/post-receive.back cp PATH/TO/GIT-CORE/contrib/hooks/post-receive-email YOUR_REPO_PATH/hooks/post-receive chmod a+x YOUR_REPO_PATH/hooks/post-receive

  2. 设置 Git repository 的config

    vi YOUR_REPO_PATH/config

    [hooks] mailinglist = “Receive1@email.address,Receive2@email.address” emailprefix = “[git]” announcelist = envelopesender = “SenderSender@email.address” sendmail = /usr/sbin/sendmail showrev=

其中 mailinglist 为收件人,emailprefix 为邮件前缀,announce list 为repo创建tag时的汇总信息邮件收件人列表, evelopesender 为发件邮箱地址,sendmail 为发件程序地址,showrev 为Log打印格式。

然后推送一个提交试试。It's work!

More useful

Email Content formatted

发送的是纯文本的邮件,对于Diff信息很难辨识。我们可以通过修改post-receive脚本自定义邮件样式。 [Making Git show post-receive emails as an HTML colour formatted diff]提供了这个脚本,我就直接拿来用。

但是标题我们要求是"[ProjectName][CommitAuthor][Action][Branch]CommitLog",所以还需要自己定制。 首先是获取ProjectName,因为我们是使用GitLab作为Git repository server,它集成 gitelitolite 了,自己负责创建项目,一些MetaData并没有保存在Repo中,而是在数据库中。比如ProjectName,它没有提供YOUR_REPO_PATH/description这个文件,所以直接使用文章中的post-receive会出现项目名称为空的情况。

我就将ProjectName设置为Repo目录名称:

projectdesc=$(basename $(pwd))
projectdesc=${projectdesc%.git*}

然后我们再修改邮件标题:

Subject: ${emailprefix}[$projectdesc][$(git log --pretty=format:"%cn" -1 $describe)][${change_type}d][$short_refname]$(git log --pretty=format:"%s" -1 $describe)

其中$(git log --pretty=format:"%s" -1 $describe为获取提交日志,$describe为Commit reversion。

好了自此,邮件内容格式问题解决了。

Integrate with Gitlab

并不是所有的Repo都需要邮件绑定,不过我们可以将这些配置放到YOUR_REPO_PATH/config中作为开关。
此外Gitlab Dashboard的提交动态同样需要绑定post-receive hook,所以需要将这两个脚本整合在一起。

我们直接将Gitlab工作的那一行逻辑复制到我们的脚本中。
这里发生一个事故,我直接粘贴rpush那一行,导致其中变量引用错误,Gitlab 的默认版本不是$refname,导致提交了部分脏数据到Gitlab中,最后通过删除那部分的events数据解决。耗时半小时。

# --- Main loop
# Allow dual mode: run from the command line just like the update hook, or
# if no arguments are given then run as a hook script
if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
# Output to the terminal in command line mode - if someone wanted to
# resend an email; they could redirect the output to sendmail
# themselves
PAGER= generate_email $2 $3 $1
else
while read oldrev new rev refname
do
repo_path=`pwd`
env -i redis-cli rpush "resque:gitlab:queue:post_receive" "{\"class\":\"PostReceive\",\"args\":[\"$repo_path\",\"$oldrev\",\"$newrev\",\"$refname\",\"$GL_USER\"]}" > /dev/null 2>&1
if [ -n "$recipients" ]; then # validate repo email notify information
generate_email $oldrev $newrev $refname | send_mail
fi
done
fi

然后将这个脚本替换Gitlab默认的post-receive . 以后的项目只需要添加YOUR_REPO_PATH/confighooks邮件信息就可以触发。

##############################################

http://huangx.in/3/for-git-add-a-submit-message-notification

gitlab配置邮件通知的更多相关文章

  1. gitlab配置邮件通知功能操作记录

    之前已经介绍了gitlab的部署http://www.cnblogs.com/kevingrace/p/5651402.html但是没有配置邮箱通知功能,今天这里介绍下gitlab安装后的邮箱配置操作 ...

  2. Jenkins 配置邮件通知

    jenkins 是一个开源的自动化服务器.通过Jenkins,可以通过自动化加速软件开发过程.Jenkins管理和控制各种开发的生命周期过程,包括构建,文档,测试,包,阶段,部署,静态分析等等.您可以 ...

  3. Jenkins 配置邮件通知步骤

    Jenkins 配置邮件通知前言 可以在Jenkins 中配置邮件通知,比如在构建失败时发送邮件通知项目组来及时修复问题. Jenkins 邮件通知功能的插件主要包括: Mailer Plugin ( ...

  4. 环境部署(八):jenkins配置邮件通知

    完成基于jenkins的持续集成部署后,任务构建执行完成,测试结果需要通知到相关人员.这篇博客,介绍如何在jenkins中配置邮件通知的方法... 一.安装邮件插件 由于Jenkins自带的邮件功能比 ...

  5. jenkins持续集成(三): jenkins配置邮件通知

    完成基于jenkins的持续集成部署后,任务构建执行完成,测试结果需要通知到相关人员.这篇博客,介绍如何在jenkins中配置邮件通知的方法... 一.安装邮件插件 由于Jenkins自带的邮件功能比 ...

  6. Ossec 安装并配置邮件通知

    Ossec 安装并配置邮件通知 目录 Ossec 安装并配置邮件通知 1. 介绍 2. 软硬件环境 3. 安装步骤 3.1 Server 3.2 Agent 3.3 配置邮件通知 4. 参考资料 1. ...

  7. Jenkins中配置邮件通知实例演示

    前言:本文通过安装配置Jenkins实现邮件通知,告知一个C# Git Repo的build成功与否 一.预配条件 在windows上安装Jenkins和它推荐安装的Plugins 创建一个@163. ...

  8. wordpress建站如何用SMTP配置邮件通知

    前提条件:你已经有了企业邮箱,相关文章请看:如何开通阿里云企业邮箱免费版(点此前往) 不建议使用主机商提供的邮箱,因为换主机商是比较常见的事情,因此导致的邮箱迁移就有些麻烦了,不如一开始就选择独立的第 ...

  9. jeakins配置邮件通知,附带解决535报错:authentication failed,如果发现测试邮件可以发出,项目构成无法发出邮件,请开启SSL认证,端口号改为(465),qq邮箱、163邮箱通用

    535报错解决方案:调用163邮箱服务器来发送邮件,我们需要开启POP3/SMTP服务,这时163邮件会让我们设置客户端授权码,这个授权码替代上面代码部分的passwd即可成功发送邮件 如果设置的邮箱 ...

随机推荐

  1. DB2常识

    1.DB2组件 appendixa. db2 database product and packaging informatin一节AESE: 高级企业服务器版(Advanced enterprise ...

  2. [转载] TCP协议缺陷不完全记录

    原文: http://www.blogjava.net/yongboy/archive/2015/05/07/424917.html tcp是一个非常复杂并且古老的协议, 之前教科书上将的很多东西应用 ...

  3. Git 的origin和master分析 push/diff/head(转)

    1.origin/master : 一个叫 origin 的远程库的 master 分支 2.HEAD指向当前工作的branch,master不一定指向当前工作的branch 3.git  push ...

  4. CSS3_新特性预览

    一.强大的CSS选择器 以前我们通常用class. ID 或 tagname 来选择HTML元素,CSS3的选择器强大的难以置信.  它们可以减少在标签中的class和ID的数量更方便的维护样式表.更 ...

  5. activiti jbpm相关资源

    Activiti 5.16 用户手册 http://www.mossle.com/docs/activiti/index.html jBPM 4.4开发指南 http://www.mossle.com ...

  6. 慢慢聊Linux AIO

    一.What:异步IO是什么? 1. 一句话总结 允许进程发起很多I/O操作,而不用阻塞或等待任何操作完成 2. 详细说说  一般来说,服务器端的I/O主要有两种情况:一是来自网络的I/O:二是对文件 ...

  7. hiho_1079_离散化

    题目 在长度为L的宣传栏上张贴N张海报,将宣传栏分为L个长度为1的单位,海报长度为整数,且高度和宣传栏相同,左右边界和宣传栏单位之间缝隙重合(即海报总是跨越整数个单位).后贴的海报可能会覆盖之前贴的海 ...

  8. js倒计时 网上流传最多的

    <!DOCTYPE html><html><head><script src="http://libs.baidu.com/jquery/1.10. ...

  9. 【转载】PHP运行模式的深入理解

    PHP运行模式的深入理解 作者: 字体:[增加 减小] 类型:转载 时间:2013-06-03我要评论 本篇文章是对PHP运行模式进行了详细的分析介绍,需要的朋友参考下   PHP运行模式有4钟:1) ...

  10. 论APP测试中黑盒测试方案的重要性?

    运筹帷幄之中,决胜千里之外.古人足不出户,通过正确的部署就能决定千里之外战争的胜利!而于测试人员而言,制定正确的测试方案,就是日后测试就是是否顺利的决定性因素. 在整个测试过程中,对测试人员.资源以及 ...