個人這篇文章不過簡單的依據上文,介紹Jenkins提供了哪些功能。詳細你們仍是要本身學習啦~
java
官網首頁就提供了windows版本號的Jenkins安裝包。咱們可以下載一個用於學習。安裝後本身主動打開http://localhost:8080,你就能看見Jenkins的界面了。node
其它也需要安裝的是:
git
1,Jenkins是java程序,所以需要安裝JDK。
github
2,同一時候執行job需要提供repository,也就是存放Jenkins按期poll源碼的地方。咱們可以去github免費註冊一個。web
3,假設想在Jenkins中使用ant,maven等,則還需要單獨安裝。但不是必須的。
shell
啓動Jenkins
windows
Jenkins天生支持unix-like system。app
好吧,Jenkins是一個java程序,因此要執行它,僅僅需要:ssh
$ java -jar jenkins.warwebapp
咱們也可以使用nohup命令,讓Jenkins在後臺執行。
以後打開URL http://myServer:8080 就可以方便的操做Jenkins了
官網給了一個sh的樣例,用於啓動Jenkins。可以參考一下。
Alternatively, if you have a servlet container that supports Servlet 2.4/JSP 2.0, such as Glassfish v2, Tomcat 5 (or any later versions), then you can run them as services, and deployjenkins.war as you would any other war file.
For example,
you could simply place the jenkins.war file in Tomcat’s webapps directory. 此時使用的URL默認就變成:
http://localhost:8080/jenkins
同一時候Jenkins提供一些默認不會啓動的特殊的功能,參考如下的link來enable它們。
https://wiki.jenkins-ci.org/display/JENKINS/Features+controlled+by+system+properties
Jenkins的文件夾結構
和CruiseControler同樣,Jenkins需要一個文件夾來存儲相關文件:JENKINS_HOME。默以爲 ~/.jenkins。即爲user的home文件夾下的一個隱藏文件夾。咱們也可以更改JENKINS_HOME,指向咱們但願的地方。
(注意因爲是隱藏文件夾,因此需要使用ls -al 才幹看到)
JENKINS_HOME
+- config.xml (jenkins root configuration)
+- *.xml (other site-wide configuration files)
+- userContent (files in this directory will be served under your http://server/userContent/)
+- fingerprints (stores fingerprint records)
+- plugins (stores plugins)
+- jobs
+- [JOBNAME] (sub directory for each job)
+- config.xml (job configuration file)
+- workspace (working directory for the version control system)
+- latest (symbolic link to the last successful build)
+- builds
+- [BUILD_ID] (for each build)
+- build.xml (build result summary)
+- log (log file)
+- changelog.xml (change log)
假設有權限管理,則在HOME文件夾下還會有users文件夾。
從文件夾結構來看,和CruiseController很類似。當中config.xml是Jenkins重要的配置文件。咱們都知道Jenkins用於monitor多個build,而jobs這個文件夾無疑就是存儲每個build相關信息的地方。
總的來講,Jenkins文件夾結構很直白,簡潔。
備份和恢復
備份和恢復很easy,就是簡單的copy Jenkins的文件夾就行了:
All the settings, build logs, artifact archives are stored under the JENKINS_HOME directory. Simply archive this directory to make a back up. Similarly, restoring the data is just replacing the contents of the JENKINS_HOME directory from a back up.
移動/拷貝/重命名 job
由於每個jobs都有本身單獨的文件夾,咱們可以很是easy的:
1,move a job from one installation of Jenkins to another by simply copying the corresponding job directory.
,2,make a copy of an existing job by making a clone of a job directory by a different name.
3,rename an existing job by renaming a directory.
改動後運行如下的命令刷新:
http://[jenkins-server]/[command]
在這裏[command]可以是:exit 退出,restart 從新啓動, reload 重載。
建立一個Project
因爲Jenkins可以用於執行各類CI,測試,批處理任務等等,因此在Jenkins中將這些任務統稱爲「free-style software project」.
Jenkins也提供了其它類型的jobs,好比:
1,假設項目是Maven,Jenkins還提供了一種僅用於Maven Project的job。但事實上free-style software projec仍然可以用於建立Maven項目,僅僅只是這樣的更適合Maven項目,結合的更好而已。
2,也可以建立一個"Monitor an external job「用於監控外部進程。
3,或者一個Matrix project,也就是multi-configuration project。
我不肯定是否僅有這4種job,或許使用插件可以建立不少其它類型的job,你們本身看資料吧。
如下是怎樣建立一個最多見的「free-style software project"的過程:
Go to Jenkins top page, select "New Job", then choose "Build a free-style software project". This job type consists of the following elements:
Note: In software engineering, software configuration management (SCM) is the task of tracking and controlling changes in the software.
好比咱們使用的build script就是ant,在Jenkins中執行ant。在腳本文件裏,可以直接使用Jenkins提供的一些變量。
同一時候,每個job可以有多個step。好比:將執行程序定義爲step1,執行單元測試定義爲step2,生成coverage報告定義爲step3。
同一時候還可以定義post-build action。好比:生成javadoc,或清理程序執行的暫時文件文件夾等。
本身主動執行Build
觸發一個build有三種方式:
可以設置Jenkins定時檢查SVN是否發生了變化,也可以手動檢查:http://YOURHOST/jenkins/job/PROJECTNAME/pollong。也可以設置Jenkins爲post-commit,這個方式尤爲適用於那些檢查是否代碼改變會花費很是長時間的狀況。
http://YOURHOST/jenkins/job/PROJECTNAME/build
Distributed builds
Jenkins supports the "master/slave" mode, where the workload of building projects are delegated to multiple "slave" nodes, allowing single Jenkins installation to host a large number of projects, or provide different environments needed for builds/tests.
在現實中需要使用distributed builds狀況很是多,好比:一個web application的build,需要分別驗證firefox和IE的行爲,那麼就需要到windows機器上執行IE。
或因爲性能問題,將build分佈到多個slave節點去。
到Jenkins的管理界面,就可以方便的加入節點。配置節點時,需要提供節點所在的機器,登錄usernamepassword,使用的文件夾等。
但是slave並不需要再安裝Jenkins。jenkins會本身主動啓用slave agent,將build需要tools考到遠程機器上。
需要注意的是:the build results and artifacts will always end up on the master server. 所以不需要跑到各個節點去查看build產生的文件,log等。
事實上在slave節點,會建立一個本地的workspace,並在執行時使用這個workspace。因爲畢竟build執行在slave節點上,因此這個節點確定要有執行build需要的所有因素。
總之加入節點並遠程執行build真是太方便了~
加入節點後,在master Jenkins home文件夾下會出現關於該節點的配置文件。
Jenkins將本身主動決定在哪一個節點上執行build,依據下列策略:
Some slaves are faster, while others are slow. Some slaves are closer (network wise) to a master, others are far away. So doing a good build distribution is a challenge. Currently, Jenkins employs the following strategy:
Jenkins經過執行slave agents來完畢分佈式build。最多見的狀況是:slave agent執行在各個slave 節點。master經過SSH遠程啓動/中止slave agent,進而控制各個節點的行爲。
一共同擁有下列4種方式啓動slave agent:
•The master starts the slave agents via ssh
• Starting the slave agent manually using Java Web Start
• Installing the slave agent as a Window service
• Starting the slave agent directly from the command line on the slave machine from the command line
需要注意的是這4種方式適用於不一樣的狀況,好比slave節點在防火牆後,致使master沒法經過SSH啓停slave agent。此時僅僅能用後三種方式,但是每每有一些弊端,比方master沒法本身主動中止/從新啓動 slave agent.
一旦加入node成功,你就可以在job中指定這個job在哪一個node執行:
Restrict where this project can be run (假設不指定則由Jenkins自行決定,即可以在slave節點執行,也可以在master節點執行,甚至在一次build中就可以自行來回切換)。
配置Jenkins,讓它收集不少其它的log
https://wiki.jenkins-ci.org/display/JENKINS/Logging
我想這對於初學Jenkins的人,用來推斷問題所在太實用了。
在流行持續集成的今天,咱們在各個環境:alpha,beta和production 都部署了惟一的Jenkinsserver。
Jenkinsserver統一負責該環境內所有組件的持續集成。也就是說,一個Jenkinsserver會有很是多個build。因此有時會用到上面提到的」Monitor an external job「。
但不是Distributed Builds。
同一時候由於Jenkins會進入每個環境,包含production,所以會使用auto deployment的方式,本身主動完畢Jenkins在各個環境的部署。
用戶管理
毫無疑問Jenkins中需要實用戶管理的功能,因爲除開發者外,有多種角色的人需要查看build的結果。
在Jenkins中的系統管理中,可以設置「不論什麼用戶可以作不論什麼事」 或 「登陸用戶可以作不論什麼事」。
所以前一個選項意味着,不論什麼瀏覽JenkinsURL的用戶都可以改動Jenkins。或僅僅有登陸用戶才幹作改動。
因此我把Jenkins中的用戶劃分爲兩類:可登陸用戶和不可登陸用戶。
1,僅僅要是改動過repository,即對build產生過影響的用戶,都會被Jenkins記錄在本地的database中。這類用戶咱們可以在Jenkins界面->查看用戶中瀏覽。
但這類用戶不是正式的Jenkins用戶,也不能登陸Jenkins。這類用戶的權限由上面說的系統管理中的配置決定。一般僅僅有查看build的權限,沒有改動權限。
2,僅僅有在Jenkins中明白註冊的用戶,才能夠登陸Jenkins,並且有權限控制。同一時候註冊過的用戶,在JENKINS_HOME文件夾下的users文件夾下,都有一個單獨的文件夾來存儲相關信息。我不太清楚是否能夠經過copy/paste將用戶部署到其它地方去,回頭測試一下。
既然要知足各類人對jenkins使用的各類需求,所以權限管理遠沒有這麼簡單。詳細你們還得本身去看啊~
Jenkins Script Console
Jenkins提供了一個script console Groovy script which allows to run arbitrary scripts on the Jenkins server or on slave nodes. This feature can be accessed from the "manage Jenkins" link。
也可以經過URL直接訪問:http://myserver:8080/hudson/script
惋惜僅僅能用Groovy 反證我不懂。