我想使用jenkins部署到测试环境和生产环境。为此,我需要连接到所需环境的服务器,比如ssh/scp。
我想知道最好的方法是什么。
我发现一些插件可以做到这一点,比如Jenkins-Deploy-Plug-in或Jenkins Publish over SSH插件。第一种方法有很多问题,部署到生产环境中并不值得信任,而第二种方法需要更改全局配置,这对于每次部署都是手动的。
有什么办法解决这个问题吗?也许可以使用一些脚本或插件?
我目前唯一的想法是:与jenkins连接到一个服务器(可能使用SSH插件),并在那里执行一个连接到所希望的环境的脚本。但这是两个联系。这真的有必要吗?我希望有一种更直接的方式来解决这个问题。
谢谢你的任何提示。
发布于 2012-12-21 00:45:30
我建议执行以下步骤:
只有一个shell脚本(存储在jenkins服务器上的某个地方)就可以完成所有工作。基本上,该脚本对构建工件执行scp,然后连接到服务器(ssh),并执行部署所需的所有任务(设置维护页面、备份当前应用程序、部署新应用程序等)。
在jenkins服务器上,至少有两个作业:
它不需要任何“特殊的”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"发布于 2012-12-21 23:46:38
使用SSH会损害环境中的安全性
并且很难排除故障。
最好在远程计算机上安装Jenkins-Slave
并通过在Slave上执行作业来运行测试。
Slave由Server监控,省去了很多麻烦
管理连接。
您可以在成功构建结束时触发远程作业
并将该构建的工件传递给它。
(也可以让第一个作业将工件存储在共享驱动器上
并将这些工件的位置传递给下一个Job)。
请看这里:
-
发布于 2014-12-15 01:20:30
理想情况下,您应该使用诸如Fabric或Capistrano之类的东西进行部署,并从Jenkins调用这些脚本。我在Ruby On Rails和非Ruby应用程序中都广泛使用过Capistrano。我看到的最大优势是:
https://stackoverflow.com/questions/13976373
复制相似问题