官网http://jenkins-ci.org/
2.安装jdk2.1解压jdk-7u51-linux-x64.tar.gz
sudo tar -xvf jdk-7u60-linux-x64.tar.gz
2.2复制解压后的目录
sudo mv jdk1.7.0_60/ /usr/local/jdk
2.3更改环境变量
sudo vim /etc/profile
在最后添加以下内容
JAVA_HOME=/usr/local/jdk1.7.0_60
CLASS_PATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASS_PATH PATH
# source /etc/profile
2.4更改为默认的JDK
(如果原来安装过JDK的)
sudo update-alternatives --install /usr/bin/java java /usr/local/jdk/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/local/jdk/bin/javac 300
sudo update-alternatives --config java
sudo update-alternatives --config javac
3.1直接安装(不推荐)
切换到jenkins.war所在目录,输入如下命令:
$ java -jar jenkins.war
然后在浏览器中(推荐用火狐)输入"http://IP:8080"即可进入jenkins的管理界面。
3.2使用tomcat做容器
3.2.1安装配置tomcat
# sudo tar xvf apache-tomcat-7.0.52.tar.gz
# sudo mv apache-tomcat-7.0.52 /usr/local/tomcat
//给tomcat添加JAVA主目录
#sudo vim /usr/local/tomcat/bin/catalina.sh ---96行
JAVA_HOME=/usr/local/jdk1.7.0_60
JRE_HOME=/usr/local/jdk1.7.0_60
CATALINA_HOME=/usr/local/tomcat
//启动脚本
# sudo cp /usr/local/tomcat/bin/catalina.sh /etc/init.d/tomcat
# chmod +x /etc/init.d/tomcat
//修改脚本并添加到开机启动项管理
# vim /etc/init.d/tomcat
---------------------------------------------------------------------------------------------
#!/bin/sh #在行首下添加
#
# tomcat Start tomcat
#
# chkconfig: 2345 08 92
# description: Starts, stops and saves tomcat
#
# config: /usr/local/tomcat/conf/
#
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop tomcat
# Description: Start, stop and save tomcat
### END INIT INFO
---------------------------------------------------------------------------------------------
# chkconfig --add tomcat
# chkconfig tomcat on
//tomcat配置用户管理(可跳过)
# pwd
/usr/local/tomcat/conf
# vim tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="tomcat" roles="admin-gui,manager-gui"/>
3.2.2将jenkins.war文件放入tomcat下的webapps目录下
$ sudo cp jenkins.war /usr/local/tomcat/webapps/
# /etc/init.d/tomcat start #若tomcat已启动,需要重新启动tomcat
启动jenkins时,会自动在webapps目录下建立jenkins目录,所以在地址栏上需要输入的地址于上一种方法有点不一样:
http://IP:8080/jenkins
出现的问题:
使用tomcat作为jenkins的容器时,选择系统管理后会出现如下提示:
Your container doesn't use UTF-8 to decode URLs. If you use non-ASCII characters as a job name etc, this will cause problems. See Containers and Tomcat i18n for more details.
意思是tomcat容器没有使用UTF-8编码,所以不能使用 中文作为任务名称,可以在tomcat中进行配置。
# sudo vim /usr/local/tomcat/conf/server.xml #添加加粗红色部分内容
<Connector port="8989" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"URIEncoding="UTF-8"/>
4.jenkins--URL选项http://IP:8080/[command]
exit :关闭jenkins,不建议使用这个功能,它会关闭jenkins所在的服务器。
restart :重启jenkins
script: 执行Groovy scripts
5.安装配置maven下载地址:http://maven.apache.org/download.cgi
# sudo tar xvf apache-maven-3.2.2-bin.tar.gz
# sudo mv apache-maven-3.2.2 /usr/local/maven
# sudo vim /etc/profile
MAVEN_HOME=/usr/local/maven
PATH=$MAVEN_HOME/bin:$PATH
# sudo source /etc/profile
# mvn -version
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T21:51:42+08:00)
Maven home: /usr/local/maven
Java version: 1.7.0_55, vendor: Oracle Corporation
Java home: /usr/local/jdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-358.el6.x86_64", arch: "amd64", family: "unix"
注意:不要勾选自动安装
源码管理方式选择Subversion
增加Post Steps
也可以是python、perl脚本。
ssh免密钥登陆 在客户端操作
ssh-keygen -t rsa #不要输入任何内容
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.16.201 #将密钥上传到服务器 需要输入一次服务器密码
chmod +x /scripts/test.sh
test.sh主要内容
scp /root/.jenkins/jobs/ncg/workspace/target/nconverge-pms-omp-0.1.0-SNAPSHOT.jarroot@192.168.16.201:/soft #将jar包上传到指定目录
ssh -f root@192.168.16.201 /soft/test1.sh #远程执行服务器端脚本
test1.sh内容依实际情况调整
8.1安装Email-ext plugin
安装过程很容易失败,多试几次