git 如何在本地执行 Capistrano 任务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8692664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I execute a Capistrano task locally?
提问by Daniel
I have defined a custom Capistrano task that's supposed to run locally (on my development machine):
我已经定义了一个应该在本地(在我的开发机器上)运行的自定义 Capistrano 任务:
desc "Push code to Dreamhost"
task :push do
run "git push dreamhost"
end
however when I try to run cap push
it executes it on the remote machine, ie.
但是,当我尝试运行cap push
它时,它会在远程机器上执行,即。
* executing `push'
* executing "git push dreamhost"
servers: ["ec2-999-99-999-999.compute-1.amazonaws.com"]
how do I get it to execute locally instead?
我如何让它在本地执行?
回答by patcon
Or use run_locally
to run natively with Capistrano, and still get proper logging and all that good stuff
或者使用run_locally
Capistrano 在本地运行,并且仍然可以获得正确的日志记录和所有好东西
回答by Cydonia7
I suggest using :
我建议使用:
system("git push dreamhost")
or
或者
output = %x[git push dreamhost]
That's just plain Ruby !
那只是普通的 Ruby !
回答by Matthew McMillan
For the commenter that mentioned run_locally doesn't show output, you have to dump the output to a variable and then print it to see it. Like this:
对于提到 run_locally 不显示输出的评论者,您必须将输出转储到一个变量,然后打印它以查看它。像这样:
task :testing_run_locally do
output = run_locally "hostname"
puts "OUTPUT: " + output
end
The downside is you won't see any output until the command has finished. Not a big deal for commands that don't run long but something that runs for several minutes will cause the deploy to appear like it is hung until it finishes. There is an open pull request for Capistrano that adds real time command output to run_locally: https://github.com/capistrano/capistrano/pull/285
缺点是在命令完成之前您不会看到任何输出。对于运行时间不长的命令来说没什么大不了的,但是运行几分钟的命令会导致部署看起来像是挂起直到它完成。Capistrano 有一个开放的拉取请求,可以将实时命令输出添加到 run_locally:https: //github.com/capistrano/capistrano/pull/285
回答by Sebastien Varrette
You can also use:
您还可以使用:
require 'rake' # Access to sh command
[...]
desc "Push code to Dreamhost"
task :push do
sh "git push dreamhost"
end