Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7748721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:51:25+00:00 2026-06-01T10:51:25+00:00

Snippet from deploy.rb task :prod1 do set :deploy_to, /home/project/src/prod1 end task :prod2 do set

  • 0

Snippet from deploy.rb

task :prod1 do
  set :deploy_to, "/home/project/src/prod1"
end

task :prod2 do
  set :deploy_to, "/home/project/src/prod2"
end

I have 2 tasks like the above. Now instead of manually running either “cap prod1 deploy” or “cap prod2 deploy”, I want to create a task “prod” which sets the required “deploy_to” based on the existence of a file on the server.

something like:

task :prod do
  if (A_FILE_IN_SERVER_EXISTS)
    set :deploy_to, "/home/project/src/prod2"
  else 
    set :deploy_to, "/home/project/src/prod1"
end

How do I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:51:27+00:00Added an answer on June 1, 2026 at 10:51 am

    You can do that like this:

    task :set_deploy_to_location do
      if capture("[ -f /etc/passwd2 ] && echo '1' || echo '0'").strip == '1'
        set :deploy_to, "/home/project/src/prod2"
      else
        set :deploy_to, "/home/project/src/prod1"
      end
      logger.info "set deploy_to = #{deploy_to}"    
    end
    

    This will do what you need. You can hook this method using before and after hooks like this:

    before :deploy, :set_deploy_to_location
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following snippet from my code: switch ($extention) { case gif: $src
I have a maven project with the following POM snippet: <modelVersion>4.0.0</modelVersion> <artifactId>Foo-Deploy</artifactId> <name>Foo-Deploy</name> <packaging>pom</packaging>
Here's a snippet of code from a shell script I have written: for src
Below is a code snippet from a book. Why can serialNumber still be set
Here is a code snippet from my project: template<typename Second, typename First = const
I have this Perl snippet from a script that I am translating into Python.
Here's a snippet from my csproj file: <ProjectReference Include=..\program_data\program_data.csproj Condition='$(Configuration)'=='Debug'> <Project>{4F9034E0-B8E3-448E-8794-CF9B9A5E7D46}</Project> <Name>program_data</Name> </ProjectReference> What
The following is a snippet from a script I have that tries to tar
So I have an XML file in the format: <projectlist> <project> <name>test</name> <type>deploy</type> <environment>dev</environment>
Here's a code snippet from OpenJDK6's hotspot/src/share/vm/prims/unsafe.cpp (starting on line 1082): // JSR166 ------------------------------------------------------------------

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.