Reputation: 19
In GitLab CI i have two variables: USER AND HOST.
In envoy.plade I want to get this:
@servers(['web' => 'user@host'])
I write like this:
@servers(['web' => '{{ getenv('USER') }}@{{ getenv('HOST') }}'])
But get error, how write it?
Upvotes: 1
Views: 668
Reputation: 350
<?php
//all below variables are coming from arguments passes with envoy run command
$name = isset($name) ? $name : null; //web
$task = isset($task) ? $task : null; //eg list
$command = isset($command) ? $command : null; //ls (command to run)
$ip = isset($ip) ? $ip : null; //suppose host is 127.0.0.1
$user = isset($user) ? $user : null;
?>
//Server Connection settings
{{ $__container->servers([$name => [str_replace('"', '', trim($ip)]])) }}
//Task Details and add the command to run
{{ $__container->startTask($task) }}
{{$command}}
{{ $__container->endTask() }}
//Open console and in project directory where envoy installed
//envoy command will be like this
envoy run list --task=list --name=web --command=ls --ip=127.0.0.1 --user=user
Upvotes: 0
Reputation:
Utilize the Composer autoloader and add then add an environment variable like $DEPLOY_SERVER=user@host
to your .env
file.
@include('vendor/autoload.php')
@setup
(new Dotenv\Dotenv(__DIR__, '.env'))->load();
$ssh = getenv('DEPLOY_SERVER');
@endsetup
@servers(['web' => $ssh])
@story('deploy')
composer
@endstory
@task('composer')
echo "Deployment complete, you connected as: {{ $ssh }}";
@endtask
Upvotes: 2