Search code examples
rubycapistrano

How to add an if staging check to Capistrano task?


Right now in Capistrano I have it doing

execute "echo #{fetch(:stage)}"

Which echoes out "staging"

On the very next line I have

if fetch(:stage) == "staging"

Which never equals true. I tried changing it to if "staging == "staging" and it enters the body of it. Uh, what gives and how do I do a check to only run one line of code for staging.


Solution

  • fetch(:stage) is likely a symbol (it's been a while since I used capistrano). To verify this, use a more precise string representation:

    execute "echo #{fetch(:stage).inspect}"
    

    I'm betting it will print :staging. In which case you need to do

    if fetch(:stage) == :staging