简体   繁体   English

Jenkins和GitBlit的整合

[英]Integration of Jenkins and GitBlit

Is there a way to configure Jenkins and GitBlit so that builds are run automatically whenever a new code is pushed to git? 有没有一种方法可以配置Jenkins和GitBlit,以便在将新代码推送到git时自动运行构建?

I've heard about using hook and post-jenknkins scripts in GitBlit and configuring 'Poll SCM' in Jenkins but perhaps there are more sophiscated configurations? 我听说过在GitBlit中使用钩子和后jenknkins脚本,并在Jenkins中配置“轮询SCM”,但也许还有更多复杂的配置?

Thanks a lot. 非常感谢。

There are two ways to use Jenkins and GitBlit to build your code. 有两种使用Jenkins和GitBlit生成代码的方法。 The first is to have Jenkins poll your SCM (GitBlit in this case) for changes, and the second is to set up a post-receive hook in Gitblit. 第一种是让Jenkins轮询您的SCM(在本例中为GitBlit)以查找更改,第二种是在Gitblit中设置一个接收后挂钩。

Polling GitBlit for changes is the simplest to set up but comes with additional overhead on the server Jenkins is running on. 轮询GitBlit以进行更改是最简单的设置,但是在运行Jenkins的服务器上会产生额外的开销。 The basic premise is Jenkins will clone your repo and compare against its previous clone to look for changes. Jenkins的基本前提是将克隆您的存储库,并将其与先前的克隆进行比较以查找更改。 If there is a difference it triggers a build. 如果存在差异,则会触发构建。 With many jobs and several repositories this could really tax your jenkins server and possibly the gitblit server as well. 有了许多工作和几个存储库,这实际上可能会使您的jenkins服务器以及gitblit服务器负担很多。 To set this up simply check the Poll SCM box and choose a schedule. 要进行设置,只需选中“轮询SCM”框,然后选择时间表。 The schedule field uses cron syntax and clicking on the ? Schedule字段使用cron语法,然后单击?。 next to the field will provide you with an example. 字段旁边将为您提供示例。

Setting up a post-receive hook is more complicated but provides you with true build-on-commit semantics. 设置接收后钩子更为复杂,但是为您提供了真正的提交时构建语义。 Now there are two ways to do this in Jenkins, Remote Trigger or use Gitblit's jenkins hook. 现在,在Jenkins中有两种方法可以做到这一点:远程触发器或使用Gitblit的jenkins挂钩。 Remote Trigger requires you to create a token for each job that is then sent to the job. 远程触发器要求您为每个作业创建一个令牌,然后将其发送到该作业。 Since this token is specific to the job Jenkins is building you'll have add a new job/token pair for each job running against each repository. 由于此令牌特定于Jenkins正在构建的作业,因此您将为针对每个存储库运行的每个作业添加一个新的作业/令牌对。 While this isn't a resource waste for Jenkins or GitBlit, it does waste your time maintaining these pairs. 虽然这对于Jenkins或GitBlit来说不是资源浪费,但确实会浪费您的时间来维护这些对。

GitBlit's jenkins hook is simple and you can use it either globally or for specific repositories. GitBlit的詹金斯挂钩很简单,您可以在全局或特定存储库中使用它。 To enable this, edit jenkins.groovy found in ${appserver.base}/groovy where ${appserver.base} is where ever you set that to be during installation. 为此,请编辑在$ {appserver.base} / groovy中找到的jenkins.groovy,其中$ {appserver.base}是您在安装过程中设置的位置。 Edit the def jenkinsUrl = gitblit.getString('groovy.jenkinsServer', 'http://your/jenkins/url') line with the URL of your Jenkins server. 使用您的Jenkins服务器的URL编辑def jenkinsUrl = gitblit.getString('groovy.jenkinsServer', 'http://your/jenkins/url')行。 You could also just set the groovy.jenkinsServer in your gitblit.properties file. 您也可以在gitblit.properties文件中设置groovy.jenkinsServer。 To force all repositories to use this hook script add it to the groovy.postReceiveScripts line in your gitblit.properties file. 要强制所有存储库使用此挂钩脚本,请将其添加到gitblit.properties文件中的groovy.postReceiveScripts行。 Otherwise edit your repository in the GitBlit web app and add jenkins to its post-receive hook list. 否则,请在GitBlit Web应用程序中编辑存储库,并将jenkins添加到其接收后挂钩列表中。

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

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