{"action":"created","issue":{"url":"https://api.github.com/repos/deployphp/deployer/issues/604","repository_url":"https://api.github.com/repos/deployphp/deployer","labels_url":"https://api.github.com/repos/deployphp/deployer/issues/604/labels{/name}","comments_url":"https://api.github.com/repos/deployphp/deployer/issues/604/comments","events_url":"https://api.github.com/repos/deployphp/deployer/issues/604/events","html_url":"https://github.com/deployphp/deployer/issues/604","id":144917537,"number":604,"title":"Use of Gitlab CI environment variables","user":{"login":"qodeboy","id":543453,"avatar_url":"https://avatars.githubusercontent.com/u/543453?v=3","gravatar_id":"","url":"https://api.github.com/users/qodeboy","html_url":"https://github.com/qodeboy","followers_url":"https://api.github.com/users/qodeboy/followers","following_url":"https://api.github.com/users/qodeboy/following{/other_user}","gists_url":"https://api.github.com/users/qodeboy/gists{/gist_id}","starred_url":"https://api.github.com/users/qodeboy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qodeboy/subscriptions","organizations_url":"https://api.github.com/users/qodeboy/orgs","repos_url":"https://api.github.com/users/qodeboy/repos","events_url":"https://api.github.com/users/qodeboy/events{/privacy}","received_events_url":"https://api.github.com/users/qodeboy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-31T14:26:23Z","updated_at":"2016-03-31T14:39:31Z","closed_at":null,"body":"| Q                 | A\r\n| ----------------- | ---\r\n| Issue Type        | Question/Bug\r\n| Deployer Version  | Deployer version 3.1.2\r\n| Local Machine OS  | Ubuntu 14.04.4 LTS x86_64\r\n| Remote Machine OS | Ubuntu 14.04.4 LTS x86_64\r\n\r\n### Description \r\n\r\nHere is our use-case, which I'm trying to implement. We have an GitLab CI server, with a build script configured to run tests and if none failed run deployer to deploy release to the server.\r\n\r\nTo not expose sensitive information to other developers (like SSH password), CI server is configured to export needed environment variables on build. The idea here is to have deployed pickup those exported variables and use them for SSH authentication.\r\n\r\nThe issue is that I can not configure deployer to pickup those variables. I have tried 2 methods:\r\n\r\n1. Set deployer env variable with a value from bash env variable, and then use them in server configuration:\r\n\r\n```\r\nenv('ssh_production_username', function () {\r\n    return runLocally('echo $DEPLOYER_PRODUCTION_USERNAME')->toString();\r\n});\r\n\r\nenv('ssh_production_password', function () {\r\n    return runLocally('echo $DEPLOYER_PRODUCTION_PASSWORD')->toString();\r\n});\r\n```\r\n\r\n2. Run `runLocally` directly in server configuration, as shown in below listing.\r\n\r\nNeither of these 2 method worked for me.\r\n\r\nCan you please review and let me know what I'm doing wrong. The goal in to read bash environment variable values and pass them to server configuration.\r\n\r\nP.S. I have double checked with `export` command, and needed variables correctly exported by CI server.\r\n\r\n### Content of `deploy.php`\r\n```php\r\n<?php\r\n\r\nrequire 'deploy/recipes/laravel.php';\r\n\r\n// Set configurations\r\nset('repository', '...');\r\n\r\nset('shared_files', ['.env']);\r\n\r\nset('shared_dirs', [\r\n    'storage/app',\r\n    'storage/framework/cache',\r\n    'storage/framework/sessions',\r\n    'storage/framework/views',\r\n    'storage/logs',\r\n]);\r\n\r\nset('writable_dirs', ['bootstrap/cache', 'storage', 'vendor']);\r\n\r\n// configure servers\r\nserver('production', 'production.domain.com')\r\n    ->user(runLocally('echo $DEPLOYER_PRODUCTION_USERNAME')->toString())\r\n    ->password(runLocally('echo $DEPLOYER_PRODUCTION_PASSWORD')->toString())\r\n    ->env('deploy_path', '/path/to/httpdocs');\r\n\r\n// migrate database\r\ntask('database:migrate', function () {\r\n    run('php {{release_path}}/' . 'artisan migrate --force');\r\n})->desc('Migrate database');\r\n\r\n// optimize application\r\ntask('deploy:optimize', function () {\r\n    run('php {{release_path}}/' . 'artisan optimize');\r\n    run('php {{release_path}}/' . 'artisan route:cache');\r\n    run('php {{release_path}}/' . 'artisan config:cache');\r\n})->desc('Optimize Application');\r\n\r\n// restart php-fpm after deployment\r\ntask('php-fpm:restart', function () {\r\n    run('sudo /usr/sbin/service plesk-php70-fpm restart');\r\n})->desc('Restart PHP-FPM service');\r\n\r\n// main deployment task\r\ntask('deploy', [\r\n    'deploy:prepare',\r\n    'deploy:release',\r\n    'deploy:update_code',\r\n    'deploy:vendors',\r\n    'deploy:shared',\r\n    'deploy:symlink',\r\n    'database:migrate',\r\n    'deploy:optimize',\r\n    'cleanup',\r\n    'php-fpm:restart',\r\n])->desc('Deploy your project');\r\n\r\n// report success after deployment successfully finished\r\nafter('deploy', 'success');\r\n```\r\n\r\n### Output log\r\n```\r\n$ dep deploy production -vvv\r\nPHP Fatal error:  Uncaught exception 'RuntimeException' with message 'Key `` is invalid' in phar:///usr/local/bin/dep/src/Type/DotArray.php:59\r\nStack trace:\r\n#0 phar:///usr/local/bin/dep/src/Type/DotArray.php(140): Deployer\\Type\\DotArray->explodeKey(NULL)\r\n#1 phar:///usr/local/bin/dep/src/Server/Environment.php(149): Deployer\\Type\\DotArray->offsetSet(NULL, NULL)\r\n#2 phar:///usr/local/bin/dep/src/functions.php(568): Deployer\\Server\\Environment::setDefault(NULL, NULL)\r\n#3 phar:///usr/local/bin/dep/src/functions.php(316): env()\r\n#4 /home/gitlab-runner/builds/8c992323/0/WeQubit/waremakers/deploy.php(22): runLocally('echo $DEPLOYER_...')\r\n#5 phar:///usr/local/bin/dep/bin/dep(60): require('/home/gitlab-ru...')\r\n#6 /usr/local/bin/dep(4): require('phar:///usr/loc...')\r\n#7 {main}\r\n  thrown in phar:///usr/local/bin/dep/src/Type/DotArray.php on line 59\r\n\r\nERROR: Build failed with: exit status 1\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/deployphp/deployer/issues/comments/203968758","html_url":"https://github.com/deployphp/deployer/issues/604#issuecomment-203968758","issue_url":"https://api.github.com/repos/deployphp/deployer/issues/604","id":203968758,"user":{"login":"qodeboy","id":543453,"avatar_url":"https://avatars.githubusercontent.com/u/543453?v=3","gravatar_id":"","url":"https://api.github.com/users/qodeboy","html_url":"https://github.com/qodeboy","followers_url":"https://api.github.com/users/qodeboy/followers","following_url":"https://api.github.com/users/qodeboy/following{/other_user}","gists_url":"https://api.github.com/users/qodeboy/gists{/gist_id}","starred_url":"https://api.github.com/users/qodeboy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qodeboy/subscriptions","organizations_url":"https://api.github.com/users/qodeboy/orgs","repos_url":"https://api.github.com/users/qodeboy/repos","events_url":"https://api.github.com/users/qodeboy/events{/privacy}","received_events_url":"https://api.github.com/users/qodeboy/received_events","type":"User","site_admin":false},"created_at":"2016-03-31T14:39:31Z","updated_at":"2016-03-31T14:39:31Z","body":"Was able to reproduce this even with minimal configuration:\r\n\r\n`deploy.php`:\r\n```php\r\n<?php\r\n\r\nlocalServer('localhost');\r\n\r\nvar_dump(runLocally('echo $FOO')->toString());\r\n```\r\n\r\nThen to test execute on terminal:\r\n\r\n1. Export test variable:\r\n```\r\n$ export FOO=bar\r\n```\r\n\r\n2. Confirm variable is exported and available:\r\n```\r\n$ echo $FOO\r\nbar\r\n```\r\n\r\n3. Run deployer on local server:\r\n```\r\n$ dep local -vvv\r\nPHP Fatal error:  Uncaught exception 'RuntimeException' with message 'Key `` is invalid' in phar:///usr/local/bin/dep/src/Type/DotArray.php:59\r\nStack trace:\r\n#0 phar:///usr/local/bin/dep/src/Type/DotArray.php(140): Deployer\\Type\\DotArray->explodeKey(NULL)\r\n#1 phar:///usr/local/bin/dep/src/Server/Environment.php(149): Deployer\\Type\\DotArray->offsetSet(NULL, NULL)\r\n#2 phar:///usr/local/bin/dep/src/functions.php(568): Deployer\\Server\\Environment::setDefault(NULL, NULL)\r\n#3 phar:///usr/local/bin/dep/src/functions.php(316): env()\r\n#4 /root/deployer-test/deploy.php(5): runLocally('echo $FOO')\r\n#5 phar:///usr/local/bin/dep/bin/dep(60): require('/root/deployer-...')\r\n#6 /usr/local/bin/dep(4): require('phar:///usr/loc...')\r\n#7 {main}\r\n  thrown in phar:///usr/local/bin/dep/src/Type/DotArray.php on line 59\r\n```"}}