I'm developing a deployment script which makes some extra tasks. Those tasks require some sensitive passwords so I thought about Laravel .env variables to avoid hardcoding them. Is it possible to use my declared .env variables within Envoy tasks?
Asked
Active
Viewed 2,517 times
0
-
[This](https://jag.gy/my-envoy-deployment-script/) article seems to suggest you can! – Lei Nelissen Aug 09 '16 at 22:21
-
a replacement for the not working link above: https://web.archive.org/web/20161224091102/https://jag.gy/my-envoy-deployment-script/ – ismaail E.G. Feb 04 '18 at 02:16
2 Answers
1
The following is what has allowed me to properly use environment variables with Envoy:
@include('vendor/autoload.php');
@setup
$dotenv = new \Dotenv\Dotenv(__DIR__);
$dotenv->load();
@endsetup
@servers(['staging' => getenv('STAGING_SSH_HOST')])
## Get remote git status.
@task('git.status', ['on' => 'staging'])
echo "Fetching git status on staging environment ..."
cd {{ getenv('STAGING_ROOT') }}
git status
@endtask
The very similar approach presented by drinke9 did not work for me, I had to use this specific setup.

user2094178
- 9,204
- 10
- 41
- 70
0
@task('env')
db_name=$(cat .env | grep DB_USERNAME)
echo $db_name
@endtask
OR
@include('vendor/autoload.php')
@servers(['web' => 'foot@xxx.xxxx.com'])
@setup
Dotenv\Dotenv::create(__DIR__)->load();
$db=$_ENV['DB_DATABASE']
@endsetup
@task('env')
echo {{$db}}
@endtask

drinke9
- 1
- 3