我想使用Jenkins进行生产部署,并寻找一种安全且合规的可接受方法。
一点背景
当前方法
是正确的选择,还是我们应该将Jump Server用作代理,然后SSH到其他计算机?
如果我们采用另一种方法,即将服务器跳转为代理,那么运行诸如git pull / fetch,服务启动-停止等命令作为ssh命令的参数是否可行?
我为此方法使用的当前脚本看起来像这样-
ssh username@production-server bash -c "'
sudo systemctl stop nginx
cd /home/username/code
git fetch --all
git checkout "$branch_name"
sudo cp /home/username/code/index.html /usr/share/doc/HTML/index.html
sudo systemctl start nginx
'"
另外,此脚本后面还会有一些if-else语句。所以总结一下我的问题
是否可以直接在Jenkins中将生产服务器作为代理添加(Jenkins只有特权人员可以访问)并运行这种命令/脚本,或者将Jump server添加为代理,然后在ssh上运行命令/脚本作为参数,可以吗?
欢迎其他最佳方法/建议!
最佳答案
add the production server as an agent in my Jenkins to save ourself from the complexity of login to Jump server and then ssh to the production server
在与我合作的机构中,这永远是不可能的:SSH始终被阻止,除非通过跳转服务器。
实际上,任何部署都由Ansible完成,它确实具有到产品服务器的SSH连接授权。 Jenkins 在那里触发
tower-cli
,启动Ansible工作。
关于git - 在生产服务器上使用Jenkins进行部署的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62775387/