1. 程式人生 > >用git做持續整合

用git做持續整合

先mark一下,準備研究這個。慢慢寫。。。。。

一般使用git做CI的基本的work flow是這樣的:

1)有可供CI Server使用的repo;

2) 開發push特定的branch到report,通常是master

3)CI Server自動檢測到changes然後執行build

4)執行對應的單元測試

5) CI Server給reporsitory打tag並release

github 和git的關係:

git是版本控制系統,和CVS等是一個概念,而github是基於git的網站,用於給使用者提供git 服務

關於git和github之間的區別:

   1.What is the difference between Git and GitHub?

      Git is a version control system; think of it as a series of snapshots (commits) of your code. You see a path of these snapshots, in which order they where created. You can make branches to experiment and come back to snapshots you took.
      GitHub, is a web-page on which you can publish your Git repositories and collaborate with other people.
   2.  Is Git saving every repository locally (in the user's machine) and in GitHub?
      No, it's only local. You can decide to push (publish) some branches on GitHub.
   3. Can you use Git without GitHub? If yes, what would be the benefit for using GitHub?

      Yes, Git runs local if you don't use GitHub. An alternative to using GitHub could be running Git on files hosted on Dropbox, but GitHub is a more streamlined service as it was made especially for Git.
   4
          How does Git compare to a backup system such as Time Machine?

      It's a different thing, Git lets you track changes and your development process. If you use Git with GitHub, it becomes effectively a backup. However usually you would not push all the time to GitHub, at which point you do not have a full backup if things go wrong. I use git in a folder that is synchronized with Dropbox.
   5Is this a manual process, in other words if you don't commit you won't have a new version of the changes made?

      Yes, committing and pushing are both manual.

下面講述安裝:

github的安裝:

windows環境下載github for windows:

https://windows.github.com/

安裝比較簡單,一路next之後需要一個github的賬號,完成註冊即可,註冊在網站https://github.com/

你可以選擇安裝git和也可以選擇不安裝git,直接用github的GUI

安裝完成之後可以建立一個repository然後publish到github上去。

比如我自己建立了一個,在github網站上的連結圖片是這樣的

安裝完成之後還需要安裝git

2) 安裝Jenkins for windows:

直接在jenkins的官網上下載http://jenkins-ci.org/。 可以下載war包或者下載

Or native package
一路next安裝完成

更多使用jenkins的資訊可以參考:https://wiki.jenkins-ci.org/display/JENKINS/Use+Jenkins

3)安裝git plugin, 通常情況下git plugin可以直接在jenkins的management plugin可以直接安裝,但是由於我這邊環境有防火牆看不到plugin的東西

所以只能直接在jenkins的官網上下載plugin安裝

需要一併安裝的plugin包括:

https://wiki.jenkins-ci.org/display/JENKINS/SCM+API+Plugin

https://wiki.jenkins-ci.org/display/JENKINS/Git+Client+Plugin

https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin

https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Plugin

安裝方法很簡單:

Manage Plugins-->advanced-->upload hpi 即可。 建議如果沒有防火牆的話可以直接安裝 這樣可以解決dependency的問題,不然還得自己一個下載

Preparation
scm-api Success
Preparation
ssh-credentials ssh-credentials plugin is already installed. Jenkins needs to be restarted for the update to take effect
Preparation
credentials credentials plugin is already installed. Jenkins needs to be restarted for the update to take effect
Preparation
git-client Success
Preparation
git Success

4)安裝github plugin,安裝方法同上,以及相關依賴。

https://wiki.jenkins-ci.org/display/JENKINS/Multiple+SCMs+Plugin

https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin

https://wiki.jenkins-ci.org/display/JENKINS/GitHub+API+Plugin

5)配置jenkins:配置jenkins的系統設定的git以及jdk的環境。

7)建立build的project並進行相關設定。

主要需要設定scm的git的reporsoty路徑以及build的triiger



8)checkin 一個檔案到github並同步,然後你能看到最新的變化