Capistrano:在远程部署后有条件地运行命令

发布于 2024-10-04 17:27:06 字数 432 浏览 0 评论 0原文

我想在部署完成后删除远程上的一些文件夹。我目前正在使用

task :set_permissions do

  parallel do |session|
    session.when "in?(:xb_test)", "cat #{deploy_to}test.htaccess >> #{current_path}/.htaccess"
  end

两个问题,这是执行此操作的最佳方法吗?如何在多个函数上运行这种语句而无需编写重复代码?

session.when "in?(:xb_test)" ...
session.when "in?(:xb_dev)" ...
session.when "in?(:xb_live)" ...

任何帮助将不胜感激,因为我对 Capistrano 还很陌生

I want to remove some folders on the remote once deploy has completed. I am currently using

task :set_permissions do

  parallel do |session|
    session.when "in?(:xb_test)", "cat #{deploy_to}test.htaccess >> #{current_path}/.htaccess"
  end

Two questions really, is this the best way to do this and how can I run this kind of statement on multiple functions without having to write repeat code?

session.when "in?(:xb_test)" ...
session.when "in?(:xb_dev)" ...
session.when "in?(:xb_live)" ...

Any help would be appreciated as I'm pretty new to Capistrano

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山人契 2024-10-11 17:27:06
  • 关于你的第一个问题,“这是最好的方法吗?” :

    我认为这不是最好的方法。
    “test”“dev”和“live”嗯......看起来你正在部署到不同的阶段,那么我最好使用 https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension

  • 关于你的第二个问题,“我怎样才能在多个函数上运行这种语句而无需编写重复代码?":

    capistrano deploy.rb只是一个ruby文件,你可以使用一个方法

    def htaccess_stuff
      "cat #{deploy_to}test.htaccess >> #{current_path}/.htaccess"
    end

,然后

task :set_permissions do

  parallel do |session|
    session.when "in?(:xb_test)", htaccess_stuff
  end

  • About your first question, "is this the best way to do this ?" :

    I don't think this is the best approach.
    "test" "dev" and "live" uhm... it looks like you are deploying to different stages, then I would better use https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension

  • About your second question, "how can I run this kind of statement on multiple functions without having to write repeat code ?":

    capistrano deploy.rb is just a ruby file, you can use a method

    def htaccess_stuff
      "cat #{deploy_to}test.htaccess >> #{current_path}/.htaccess"
    end

and then

task :set_permissions do

  parallel do |session|
    session.when "in?(:xb_test)", htaccess_stuff
  end

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文