使用SSH会破坏您环境的安全性 并且很难排除故障。
最好安装一个 的 詹金斯从站 强> 在远程机器上 并通过在Slave上执行Job来运行测试。
奴隶由服务器监控,这可以为您节省很多麻烦 管理连接。
您可以在成功构建结束时触发远程作业 并传递该构建的工件。 (也可以将第一个Job存储在共享驱动器上 并将这些工件的位置传递给下一个Job。
看这里:
我建议以下程序:
一个shell脚本(存储在jenkins服务器上的某个地方)可以完成所有操作。 基本上,脚本执行构建工件的scp,然后连接到服务器(ssh)并执行所有必要的部署任务(设置维护页面,备份当前应用程序,部署新应用程序,......)。
在jenkins服务器上,至少有2个作业:
它不需要任何“特殊”jenkins插件来实现这种“一键部署”。 它只要求jenkins用户具有对目标服务器的ssh访问权限。
的 编辑 强>
这是一个示例shell脚本来说明我的帖子
#This script will copy the last artifact build by the job "MyApp" to test.myserver.com #and remotely execute the deployment script. #copy the war to the server #(the job "MyApp" is using maven, that's why the war can be found at this location) scp -i <HOME_DIR>/.ssh/id_dsa $HUDSON_HOME/jobs/MyApp_Build/workspace/myapp/target/myapp.war deployeruser@test.myserver.com:/tmp/ #connect to the server and execute the deployment script ssh -i <HOME_DIR>/.ssh/id_dsa deployeruser@test.myserver.com #The following is just an example of what a deployment script can be. #of course you must adapt it to your needs and environment "cd <TOMCAT_DIR>; #first copy the current war to a backup directory (additionaly, I have a cron task deleting old undeployed apps) cp -rf myapp-apps/myapp* undeployed/myapp-apps/; #execute a script (stored on the server) to properly stop the app sh bin/myapp.sh stop; #delete current app rm -rf myapp-apps/myapp; rm -rf myapp-apps/myapp.war; #copy the uploaded war in tomcat app directory cp /tmp/myapp.war myapp-apps/; #execute a script (stored on the server) to start the app sh bin/myapp.sh start"
理想情况下,你应该使用类似的东西 布 要么 Capistrano的 用于部署,并从Jenkins调用这些脚本。我已经将Capistrano广泛用于Ruby On Rails和非Ruby应用程序。我看到的最大优势是: