简体   繁体   中英

Rake Capistrano - how to pass dynamic parameters to execute a shell command

In my Rake capistrano script, I am creating shell commands that needs to have dynamic arguments. My rake code is as below

execute "sed -i '/SPARK_HOME=/c\\export SPARK_HOME=<arg1>' #{release_path}/backend_layer/configs/hdfs/cluster.sh"

How can I call this rake and send the argument <arg1>, so that my command is dynamic

Write your rake task like below

desc 'Passing argument on rake task'
task :symlink_shared, [:arg1] => :environment do |t, args|
  execute "sed -i '/SPARK_HOME=/c\\export SPARK_HOME=#{args.arg1}' #{release_path}/backend_layer/configs/hdfs/cluster.sh"
end

then, run the cap script with argument like below

cap staging postdeploy:symlink_shared[<your_arg1>]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM