超越之Hudson配置

来源:互联网 发布:网络代理销售合作协议 编辑:程序博客网 时间:2024/05/17 04:53
Hudson配置
-----------------
1.下载hudson-3.3.3.war
http://hudson-ci.org/


2.配置环境
前提安好JDK1.7 与 tomcat7.0
将war包布到tomcat下


3.配置Hudson
1)进入后安装前3个插件
2)Manage Hudson-->Configure Security-->Hudson专有用户数据库-->安全矩阵
  添加用户/组: admin(给全部权限)、匿名用户给两个read权限
  注意:在添加完admin后是不可用的,再次注册一下admin账号才可以
3)配置JDK/MAVEN的路径
4)安装插件:
   * Hudson Subversion Plug-in
   * Publish Over SSH---远程发布服务
   * Hudson SSH plugin ---用于远程脚本调用
   * Legacy Maven 2 job type Plugin
   安装完后需要重启服务:点击出现的restart按钮


4.新建任务
1.构建一个Maven 2/3 (Legacy)项目
Job Configurations
1)Project name(项目名称):interface-ad
2)Description(项目描述):广告接口
3)Discard Old Builds(构建缓存几次):5
4)Max # of builds to keep():5
5)Subversion Authentication:需先设置好SVN的账号
* Repository URL:svn://106.3.36.158/zspr_interface/interface/interface-ad
* User name/password authentication 用户名与密码
6)Build Triggers
Build whenever a SNAPSHOT dependency is built(默认勾选)
Build after other jobs are built(当前项目依赖于其它项目时勾选)
Poll SCM---Schedule: * * * * * (每分钟触发构建)
7)Build
Root POM: pom.xml
Goals and options : clean install deploy 
8)E-mail Notification(邮件提醒,默认即可,可选项)


5.远程主机部署设置
1)配置远程主机webapps目录(一个项目设置一个对应目录, hudson系统级设置)
Publish over SSH--->SSH Servers
Name(主机名称):interface-ad(192.168.1.101)
Hostname(主机地址):192.168.1.101
Username(用户名):root
勾选:Use password authentication, or use a different key
Passphrase / Password(密码):123456
Remote Directory(远程目录):/root/
Port(端口):22
Test Configuration(测试配置):Success
2)配置项目部署目录(项目级设置)--- 将打包好的项目发布到指定目录
在新建的项目中,将Send build artifacts over SSH勾选,出现SSH PublishersSSH Server
发布的war包路径:/root/.hudson/jobs/03-interface-ad/workspace/target/interface-ad-0.0.1-SNAPSHOT.war
Name:下拉选择已建项目
Source files:target/interface-ad-0.0.1-SNAPSHOT.war (相对于/root/.hudson/jobs/springRecord/workspace/的路径)
Remove prefix:target
Remote directory:tomcat/webapps(相对于配置远程主机中的路径如:/root/)
Exec command:/tomcat/bin/deploy.sh (重启命令) 或直接写命令






deployed.sh
---------------------------
#注意:
#1)这里无需删除原有的war包,会自动将原有的war替换掉
#2)这里必须加上JAVA的环境变量设置,否则不能正常启动
# java
export JAVA_HOME=/opt/jdk1.7
export JRE_HOME=$JAVA_HOME/jre


/opt/tomcat/ad.zspuren.com-3300/bin/shutdown.sh
sleep 3
rm -rf /opt/tomcat/home.zspuren.com-1100/webapps/ROOT* #需要删除以前的ROOT.war包及ROOT目录
mv /opt/tomcat/ad.zspuren.com-3300/webapps/interface-ad-0.0.1-SNAPSHOT.war /opt/tomcat/ad.zspuren.com-3300/webapps/ROOT.war
/opt/tomcat/ad.zspuren.com-3300/bin/startup.sh


 
maven编译时错误解决:
 1)致命错误: 在类路径或引导类路径中找不到程序包 java.lang
 2)执行mvn 报错 source-7或source 1.5 中不支持 diamond运算符,在pom.xml下加入
 <build>
<plugins> 
<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-compiler-plugin</artifactId> 
<configuration> 
<source>1.7</source> 
<target>1.7</target> 
</configuration> 
</plugin> 
</plugins>
</build>


   
注意:有时重新部署时会读取原有的配置文件,这时需要手工解决
打开/root/.hudson/jobs/01-interface-config-dev/workspace/目录
删除target与src两个目录的所有文件即可:rm -rf target/* src/*




 
deploy.sh没有配置jdk,出现以下错误
-----------------------------------------
channel stopped
SSH: Failed to get hostname [zspr03: zspr03: 未知的名称或服务]
SSH: Connecting with configuration [ad.zspuren.com-3300] ...
SSH: EXEC: STDOUT/STDERR from command [/opt/tomcat/ad.zspuren.com-3300/bin/deploy.sh] ...
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
SSH: EXEC: completed after 3,207 ms
SSH: Disconnecting configuration [ad.zspuren.com-3300] ...
ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [1]]
Finished: UNSTABLE

================================================
原文:http://blog.csdn.net/cyjch/article/details/51569392
作者:超越
超越的主页:http://blog.csdn.net/cyjch
================================================

0 0
原创粉丝点击