use*_*413 35 continuous-deployment jenkins jenkins-plugins
我想用jenkins部署到测试环境和生产环境.为此,我需要连接到所需环境的服务器,例如ssh/scp.
我想知道最好的方法是什么.
我找到了一些插件来做这件事,比如Jenkins-Deploy-Plug-in或Jenkins Publish over SSH Plugin.第一个问题很多,部署到生产中并不值得信赖,第二个问题需要更改全局配置,即每个部署的手动工作.
任何想法如何解决这个问题?也许有一些脚本或插件?
我目前唯一的想法是:将jenkins连接到服务器(可能使用SSH插件)并在那里执行连接到所需环境的脚本.但这是两个联系.这真的是必要的吗?我希望有一个更简单的方法.
谢谢你的暗示.
ben*_*n75 21
我建议以下程序:
一个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"
Run Code Online (Sandbox Code Playgroud)
使用SSH会破坏您环境的安全性,
并且很难进行故障排除.
最好在远程计算机上安装Jenkins-Slave,
并通过在Slave上执行Job来运行测试.
奴隶由服务器监控,这为您节省了
管理连接的麻烦.
您可以在成功构建结束时触发远程作业,并将该构建
的工件传递给它.
(也可以将第一个作业存储在共享驱动器
上的工件,并将这些工件的位置传递给下一个作业).
看这里:
| 归档时间: |
|
| 查看次数: |
33212 次 |
| 最近记录: |