1、下载tomcat
2、下载jenkins:http://updates.jenkins-ci.org/download/war/
3、unzip tomcat
4、将jenkins.war放到tomcat\webapps下
5、tomcat\bin\startup.sh启动tomcat:./startup.sh
注:Linux中新添加的文件需添加执行权限,cd到tomcat\bin:chmod+x *
6、启动成功后登录:http://127.0.0.1:8080/jenkins
7、用户配置及创建
系统管理->configure global security->sign up
点击保存
输入数据后点击sign up
登录成功
如果还需创建更多用户:系统管理->管理用户->新建用户
8、添加插件git plugin
github plugin
系统管理->管理插件->可安装的插件->查找插件->点击安装
安装成功后可重启tomcat,也可不重启
9、生成秘钥
在Linux中生成秘钥:root@xx:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx root@xx
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |
| . |
| x x. x S |
|. o. O o . |
| x ox.* x . |
| ooxo o.x |
| xo .x.xo. |
+-----------------+
root@xx:~/.ssh$ cat id_***.pub >> authorized_keys
首先输入:ssh-keygen
会让你输入两次密码,直接回车就好,就是不设置密码
成功后在.ssh目录中执行:cat id_***.pub >> authorized_keys
*需将生成的密钥放入/var/lib/jenkins/.ssh中
10、安装gitapt-getupdate
aptitude install git
11、添加秘钥
git安装完成后返回jenkins主页,点击credentials
12、在git代码所在服务器中添加公钥
点击git服务器上的add ssh key添加
title:jenkins@IP
key:将id_rsa.pub上的内容复制
13、配置jenkins中git的路径
系统管理->系统设置
git路径,默认为:/usr/bin/git
14、创建git job
新建一个job,配置源码
构建成功后代码生成路径:
/root/.jenkins/workspace/jobname