一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

Git flow with Jenkins and GitLab

 bananarlily 2015-11-26
Juri Strumpflohner
Reading time: 1116 words - 6 min read Comments: 0
950Kudos

At work I recently helped a team to transition from TFS to using Git as their source control management. After introducing the members to Git, we also established a common workflow on how we wanted to have Git integrate with Jenkins and GitLab. Below is our current implementation.

You might be interested in my latest "Implementing the git flow" article as well.

Git branching strategies

Git branching strategies are guidelines on how to use git's branching mechanism for your development. Establishing such a shared convention is especially useful for having a common vision in the team, in order to have everyone steer in the right direction.

There are a couple of git branching strategies around which I'd not like to go into the very details right now. The interested among you might want to consider some of these links

Making git-flow work on Jenkins and GitLab

At work, one of our teams recently switched from TFS to Git where we decided to adopt a "git-flow" similar style of working, having

  • master being the main development branch,
  • production being the one containing the production releases,
  • story/<storyname> being feature branches per userstory
  • ...and some other support branches for preparing releases, hotfixes etc.

These branches get published onto our internal Git server powered by GitLab. What we obviously wanted as well is to integrate this strategy with our Jenkins build server, having

  • each checkin on master being automatically deployed in a staging/dev environment
  • each checkin to a story/ branch to be build and verified against the .Net and JavaScript unit tests (and in the future integration tests as well, hopefully)
  • each checkin to production/ to be build, tested and automatically deployed in a "production-like" environment which is currently only visible to the client, but in the future intended to be accessed by all users

Based on the above assumptions we currently create one Jenkins job per environment, one for master, one for the user story branches and one for production (although I have the feeling Jenkin's build parameterization could help out here to avoid redundancy between the build configurations...but didn't look into that, yet). Let's take a look at the master configuration as the others can be easily deduced starting from that one.

1. Source Code Management - Git Configuration

Before starting, make sure you have the Jenkins Git plugin. Then create a new Jenkins job, and in the "Source Code Management" section configure your Git repository like in the img example below.

Git configuration

In the Branch Specifier field, enter your desired branch, depending on which one you're going to build in this current job. For master simply enter */master, for building your feature/userstory branches (and given you start them with story/<name>), enter */story/* and so on.

2. GitLab Webhook

The next step is to add a web hook to GitLab. This is needed s.t. GitLab is able to signal to Jenkins about new commits that have been "pushed" to the repository. This is an alternative, but much more efficient way of instead doing a continuous polling.

Just go to your repository settings and then to Web Hooks.

Gitlab hook for communicating with Jenkins

Enter an url of the form http:///git/notifyCommit?url=git@mygitlabserver.com:myrepo.git.

3. Activate polling

The final step is to setup polling. H?? Sorry, didn't you just mention previously that we don't need polling 'cause GitLab calls Jenkins in case of new commits?? Yep, that's right, but that's part of a "security" measure the guys creating the Git plugin introduced to make sure you (that you control the Jenkins job) and you (that you added the Web Hook) both consent to execute the build based on new commits.

This will scan all the jobs that's configured to check out the specified URL, the optional branches, and if they are also configured with polling, it'll immediately trigger the polling (and if that finds a change worth a build, a build will be triggered in turn.) We require the polling configuration on the job so that we only trigger jobs that are supposed to be kicked from changes in the source tree. Source

However, in the polling configuration you don't have to specify any kind of interval, meaning that it won't start by its own. You simply tick the checkbox "Poll SCM" to give your consent (somehow).

Git polling configuration

That's it, now your Jenkins jobs should start based on the branch you configured in your job and based on the branch that gets pushed to GitLab, just as we wanted.

Alternative approaches

In case you just need to trigger the build of a branch from GitLab, you can also simply configure Jenkin's remote trigger and add that as a Web Hook to your GitLab repo

Remote trigger configuration

The downside of this approach is that you're not able to selectively launch builds based on commits on certain branches.

Finally, I also found a plugin called GitLab Hook which I didn't try yet as the above described approach was much simpler (and didn't require the installation of a plugin). On their page they write that

For GitLab [...] For Gitlab there is an existing solution that might work for you. You can just use the notifyCommit hook on Git plugin like this. [...] But, with a large number of projects that are mostly polling (no hooks), the project might actually be built with a great delay (5 to 20 minutes). You can find more details about notifyCommit and this issue here. GitLab Hook plugin page

I did not experience any of such delays so far, but we'll see.

Automatically build all feature branches

Not only with Git flow, but in general when you work with feature branches and Merge/Pull requests it makes a lot of sense to automatically build those on your build server and execute the tests in order to make sure those branches would pass the build pipeline. There are different strategies for doing so.

One possibility is to establish a naming convention for feature branches like a common prefix, i.e. feat-<name> or fix-<name>. In that way it is possible to selectively create Jenkins build jobs that monitor those branches:

Only build branches that have the prefix "userstory/<name>"

The other strategy is to simply build all branches other than master (probably a more naive approach).

  1. Under "Source Code Management" choose Git
  2. Click the "Add" button towards the end of the plugin section and choose "Strategy for choosing what to build"
build all branches other than master

This article has been re-published on the following partner sites:

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多

    日韩人妻毛片中文字幕| 欧美日韩少妇精品专区性色| 日本av一区二区不卡| 国产香蕉国产精品偷在线观看| 久久精品少妇内射毛片| 一区二区三区在线不卡免费| 中文字幕禁断介一区二区| 办公室丝袜高跟秘书国产| 伊人久久青草地综合婷婷| 日韩午夜老司机免费视频| 久草精品视频精品视频精品 | 一区二区三区四区亚洲专区| 国产精品欧美一区二区三区不卡| 中文字幕人妻日本一区二区| 色偷偷偷拍视频在线观看| 国产一级精品色特级色国产| 伊人久久青草地婷婷综合| 日本人妻丰满熟妇久久| 国产欧美日韩综合精品二区| 国产综合一区二区三区av| 亚洲专区中文字幕在线| 日本久久中文字幕免费| 成年女人午夜在线视频| 欧美日韩国产亚洲三级理论片| 日韩在线一区中文字幕| 欧美色婷婷综合狠狠爱| 欧美不卡一区二区在线视频| 中文精品人妻一区二区| 亚洲熟妇熟女久久精品 | 日韩女优精品一区二区三区| 精品日韩国产高清毛片| 熟女乱一区二区三区四区| 国产亚洲系列91精品| 欧美二区视频在线观看| 欧美极品欧美精品欧美| 欧美人妻盗摄日韩偷拍| 殴美女美女大码性淫生活在线播放 | 精品推荐久久久国产av| 国产成人精品视频一二区| 婷婷基地五月激情五月| 国产欧美一区二区三区精品视|