亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Jenkins(二)

系統 1949 0
官網:https://wiki.jenkins-ci.org/display/JENKINS/Meet+Jenkins

我的這篇文章不過簡單的依據上文,介紹Jenkins提供了哪些功能。詳細大家還是要自己學習啦~


官網首頁就提供了windows版本號的Jenkins安裝包。我們能夠下載一個用于學習。安裝后自己主動打開http://localhost:8080,你就能看見Jenkins的界面了。

其它也須要安裝的是:

1,Jenkins是java程序,因此須要安裝JDK。

2,同一時候執行job須要提供repository,也就是存放Jenkins定期poll源碼的地方。我們能夠去github免費注冊一個。

3,假設想在Jenkins中使用ant,maven等,則還須要單獨安裝。但不是必須的。


啟動Jenkins

Jenkins天生支持unix-like system。

  • 直接執行

好吧,Jenkins是一個java程序,所以要執行它,僅僅須要:

$ java -jar jenkins.war

我們也能夠使用nohup命令,讓Jenkins在后臺執行。

之后打開URL http:// myServer :8080 就能夠方便的操作Jenkins了

官網給了一個sh的樣例,用于啟動Jenkins。能夠參考一下。

  • 在Servlet container中執行

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 deploy jenkins.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:

  • optional SCM, such as CVS or Subversion where your source code resides. 指定源碼在哪。

Note: In software engineering, software configuration management (SCM) is the task of tracking and controlling changes in the software.

  • optional triggers to control when Jenkins will perform builds. 指定Jenkins何時觸發一次build。
  • some sort of build script that performs the build (ant, maven, shell script, batch file, etc.) where the real work happens 觸發build時,使用的腳本文件,比如ant。在這個腳本文件里,我們能夠從svn下載最新代碼,刪除上次build的暫時文件,創建必要文件夾,編譯源碼,執行,打包等一系列工作。
  • optional steps to collect information out of the build, such as archiving the artifacts and/or recording javadoc and test results. 收集log信息。
  • optional steps to notify other people/systems with the build result, such as sending e-mails, IMs, updating issue tracker, etc. 通知相關人員build的結果。

比如我們使用的build script就是ant,在Jenkins中執行ant。在腳本文件里,能夠直接使用Jenkins提供的一些變量。

同一時候,每一個job能夠有多個step。比如:將執行程序定義為step1,執行單元測試定義為step2,生成coverage報告定義為step3。

同一時候還能夠定義post-build action。比如:生成javadoc,或清理程序執行的暫時文件文件夾等。


自己主動執行Build

觸發一個build有三種方式:

  • Builds in Jenkins can be triggered periodically (on a schedule, specified in configuration) 這里定義schedule的語法是unix常見的cron語法。
  • Or when source changes in the project have been detected

能夠設置Jenkins定時檢查SVN是否發生了變化,也能夠手動檢查:http://YOURHOST/jenkins/job/PROJECTNAME/pollong。也能夠設置Jenkins為post-commit,這個方式尤其適用于那些檢查是否代碼改變會花費非常長時間的情況。

  • Or they can be automatically triggered by requesting the URL:

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:

  1. If a project is configured to stick to one computer, that's always honored.
  2. Jenkins tries to build a project on the same computer that it was previously built.
  3. Jenkins tries to move long builds to slaves, because the amount of network interaction between a master and a slave tends to be logarithmic to the duration of a build (IOW, even if project A takes twice as long to build as project B, it won't require double network transfer.) So this strategy reduces the network overhead.

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 反證我不懂。












Jenkins(二)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产激情久久久久影 | 人人做人人爽久久久精品 | jizzjizz亚洲女人 | 黄频网站在线观看视频 | 色婷婷色综合激情国产日韩 | 一区二区三区精品国产 | 狠狠干天天干 | 97影院理伦片| 国产视频一区二区 | 精品一区二区免费视频 | 狠狠久久久久久亚洲综合网 | 理论片 我不卡影院 | 亚洲天堂二区 | 欧美日韩国产一区二区三区欧 | 美女被羞羞产奶视频网站 | 中文字幕专区高清在线观看 | 精品一区 二区三区免费毛片 | 欧美国产永久免费看片 | 久草在线视频免费播放 | 国产综合91 | 亚洲夜色| 国产99视频在线 | 一级毛片子 | 国产系列欧美系列日韩系列在线 | 私人小影院在线 观看 | 国产精品久久成人影院 | 一七六九1769视频免费观看 | 欧美国产日产精品免费视频 | 一级一毛片a级毛片 | 亚洲欧美日韩在线精品2021 | 91精品国产高清久久久久久io | 清纯唯美亚洲综合日韩第 | 奇米影视在线视频8888 | 五月婷婷免费视频 | 亚洲日本视频在线观看 | 国产精品亚洲专区在线播放 | 中文字幕视频一区 | 日本高清视频一区二区 | 国产伦精品一区二区三区免费迷 | 亚洲天堂一区在线 | 不卡的毛片 |