简体   繁体   English

Jenkins 和 Gerrit 与 google repo scm 的集成

[英]Jenkins and Gerrit integration with google repo scm

I am writing because there is something not clear to me on how to configure jenkins to fetch from gerrit the changes for building my project.我写这篇文章是因为我不清楚如何配置 jenkins 以从 gerrit 获取构建我的项目的更改。

There is a lot of tutorial / examples on the net related to how to connect all those piece of code.网上有很多关于如何连接所有这些代码的教程/示例。 But I didn't found any that explain what I want to do.但我没有找到任何可以解释我想做的事情。 I think it's possible but... well.我认为这是可能的,但是……好吧。 I'm not sure.我不知道。

My setup: I have a repo manifest that contains a lot of different modules of the final application.我的设置:我有一个 repo 清单,其中包含最终应用程序的许多不同模块。 The app was written in this way because I can change a module and substitute it with another with similar code that do a different job.应用程序以这种方式编写,因为我可以更改一个模块并将其替换为另一个具有类似代码但可以完成不同工作的模块。 For example they can be personalization for different customers.例如,它们可以针对不同的客户进行个性化。

I setup a job in jenkins that catch every commit in each submodule.我在 jenkins 中设置了一个工作来捕获每个子模块中的每个提交。

I connected Jenkins to Gerrit and I can start the build with gerrit trigger.我将 Jenkins 连接到 Gerrit,我可以使用 gerrit 触发器开始构建。

It works and I can build my master and the current master.它有效,我可以构建我的主人和当前的主人。

My problem is that when I send a patch for review jenkins build the master, not the patch I sent.我的问题是,当我发送补丁进行审查时,詹金斯构建了主版本,而不是我发送的补丁。 I would like to test the last patch before integrating it on master.我想在将它集成到 master 之前测试最后一个补丁。

Modules cannot be built standalone because they are all connected in some way so I cannot check each part alone.模块不能独立构建,因为它们都以某种方式连接,所以我无法单独检查每个部分。

Someone was able to accomplish something like this?有人能够完成这样的事情吗?

When the Gerrit Trigger start the Jenkins job, you could execute the following to prepare the workspace before you execute the build:当 Gerrit Trigger 启动 Jenkins 作业时,您可以在执行构建之前执行以下操作来准备工作区:

  1. Use "repo sync" to checkout all repositories使用“repo sync”检查所有存储库
  2. Use the GERRIT_PROJECT and GERRIT_REFSPEC Gerrit Trigger env variables and execute the following commands to checkout the patchset of the changed repository:使用 GERRIT_PROJECT 和 GERRIT_REFSPEC Gerrit Trigger 环境变量并执行以下命令以检出已更改存储库的补丁集:

    cd $GERRIT_PROJECT cd $GERRIT_PROJECT

    git fetch https:// USER @ SERVER /a/$GERRIT_PROJECT $GERRIT_REFSPEC && git checkout FETCH_HEAD git fetch https:// USER @ SERVER /a/$GERRIT_PROJECT $GERRIT_REFSPEC && git checkout FETCH_HEAD

    OR或者

    git fetch ssh:// USER @ SERVER :29418/$GERRIT_PROJECT $GERRIT_REFSPEC && git checkout FETCH_HEAD git fetch ssh:// USER @ SERVER :29418/$GERRIT_PROJECT $GERRIT_REFSPEC && git checkout FETCH_HEAD

The key is to set accordingly the "Repositories" > "Advanced.." > "Refspec" and the "Branches to build" > "Branch Specifier" fields in: Job > Configure > Source Code Management > Git关键是相应地设置“Repositories”>“Advanced..”>“Refspec”和“Branches to build”>“Branch Specifier”字段:作业>配置>源代码管理> Git

If you want to build the "master" branch then set:如果要构建“master”分支,请设置:

Refspec = +refs/heads/master:refs/remotes/origin/master

Branch Specifier = refs/heads/master

If you want to build the patchset then set:如果要构建补丁集,请设置:

Refspec = $GERRIT_REFSPEC:$GERRIT_REFSPEC

Branch Specifieer = $GERRIT_REFSPEC

Click on the "?"点击“?” at the right of the field to see more details.以查看更多详细信息。

See the gerrit-trigger-plugin man page:请参阅gerrit-trigger-plugin手册页:

repo init -u git://gerrit.mycompany.net/mymanifest.git
repo sync
repo download $GERRIT_PROJECT $GERRIT_CHANGE_NUMBER/$GERRIT_PATCHSET_NUMBER

... does what you're looking for. ...做你正在寻找的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM