In the documentation it says
Runs a command on a remote server in the working path (server(...)->env('deploy_path', '/home/path')).
But when I run 'pwd', I found the working path was the home directory of the user. Either there is a bug or the documentation is wrong?
all command run using cd {{release_path}} && [[comman]]
This also happens when a command is run through a hook (after);
after('elgentos:test', 'elgentos:test2');
Both test and test2 commands have one line;
writeln(run('pwd'));
➜ project git:(master) ✗ dep elgentos:test staging
➤ Executing task elgentos:test
/home/elgentos/project
✔ Ok
➤ Executing task elgentos:test_next
/home/elgentos
✔ Ok
The suggestion by @ad3n does not work when the commands are not run in the deploy context, because at that point the {{release_path}} variable isn't set and an error is thrown.
Right now I'm left with two options;
within('{{deploy_path}}', function () use ($all, $my, $args) { run('whatever ' . $all . $my . $args); });
or
run('cd {{deploy_path}} && whatever ' . $all . $my . $args);
Both of which aren't elegant.
So I vote for this issue to be re-opened @elfet
Will look close on it.
There was bug with working_path, indeed. But for now it's about 1.5 years since bug was discovered. And this become default behavior. So i'm thinking to save this behavior and update docs: run executes command in user home dir. If you want to change to deploy_path used `cd1 function:
task('...', function () {
cd('{{deploy_path}}');
run('pwd');
});
Or use short syntax:
task('hook', '
cd {{deploy_path}};
pwd;
');
👁 17dcad7b3b28e6455423e26baff13f036ddb62ab
This is a :man_facepalming: kind of behavior: every task now needs to cd('{{deployment_path}}');. It breaks DRY principle + it is error prone (recipe maintainer can forget to do it or forget to change it).
I've tried before('deploy:*', 'a_hack:cd_to_deployment''); and ->set('working_path', '/path/to/deployment') both didn't work.
Usually project is residing in a single folder that is not user home directory and it makes sense to cd {{deployment_path}} for isolation and convenience. Documentation doesn't state that default directory is user home directory either.
Even if you don't want to change the default behavior it would be awesome if you would provide some workaround like optional setting default_path or similar setting to be used as a fallback in case if one needs to run all commands in given directory.
Thank you.
makes sense to cd {{deployment_path}} for isolation and convenience.
Maybe this will go to v5 (it still in beta). I don't like to cding to release path too. But i think what task should be without side effects as possible (cd in one mustn't effect working_path in another one)
default_path or similar setting
Try this:
set('working_path', '{{release_path}}');
If you can add this to docs (and more stuff what you this necessary about cding) will be really cool.
Working path didn't work :( https://github.com/deployphp/deployer/blob/master/src/Task/Task.php#L87
Yeah, this should be fixed.