源码管理这里选择Git,Repository URL就是Gerrit Web上的为匿名用户提供的地址,注意把地址中的
git clone命令去掉,Jenkins服务器自身安装了git,集成了git环境。
注意:开发人员push的代码还没有merged,是保存在gerrit上的临时分支上的,所以我们要构建的话,应该去下载临时分支上的代码去构建。而不是下载$GERRIT_BRANCH上已经merge过的代码
Refspec:设置为refs/changes/*:refs/changes/*
Bracnes to build:设置为$GERRIT_REFSPEC,这个是git插件自带的宏,还有一个宏为$GERRIT_BRANCH,表示Gerrit上的分支。下面是Jenkins官方对这两个宏的解释:
To get the Git Plugin to download your change; set Refspec to $GERRIT_REFSPEC and the Choosing strategy to Gerrit Trigger. You may also need to set 'Branches to build' to $GERRIT_BRANCH. If this does not work for you set Refspec torefs/changes/*:refs/changes/* and 'Branches to build' to $GERRIT_REFSPEC. Note: Be aware that $GERRIT_BRANCH and $GERRIT_REFSPEC are not set in the Ref Updated case. If you want to trigger a build, you can set Refspec and 'Branches to build' to $GERRIT_REFNAME.
只有这两个地方设置对,jenkins才能到gerrit上下载changes(即开发人员push的最新的代码)去构建。
构建触发器选择Gerrit event
Choose a server:选择前面配置的Gerrit Server
Trigger on:可以不配置,jenkins会默认选择 Patchset Created 和Draft Published。表示开发人员只要push代码则触发构建,这是我们期望的。Change Merged表示当代码审核通过后,并且成功地Merge后才触发构建。Comment Added:这个选项可以自定义Code Review和Verified的值来触发构建,假如我这里Trigger on选择Comment Added,并且Code Review的值选择1,那么当项目管理员审核代码时,给的值为1,就会触发构建。
下面是官网的解释:
Draft Published: Sent when a change moves from draft state to new. (only available in version 2.5 or higher of Gerrit).
Patchset Created: Sent when a new patchset arrives on a change. Before version 2.6.0, this was the only event you could trigger on.
Change Merged: Sent when a change is merged on the Gerrit server.
Comment Added: Sent when a comment is added to a change. Which category and value to trigger on can be configured. The available categories can be configured in the server settings for the plugin.
Ref Updated: Sent when a ref is updated on the Gerrit server, i.e. someone pushes past code review.