个人这篇文章不过简单的依据上文,介绍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 反证我不懂。