diff --git a/src/DeployRunner.php b/src/DeployRunner.php index 0ceef75..907fdc4 100644 --- a/src/DeployRunner.php +++ b/src/DeployRunner.php @@ -104,7 +104,7 @@ private function prepare(bool $configureBuildStage, bool $configureServers, stri $config->setLogger($this->log); if ($configureBuildStage) { - $this->initializeBuildStage($config); + $this->initializeBuildStage($config, $stage); } if ($configureServers) { @@ -204,17 +204,20 @@ private function configureStageServer(Stage $stage, Server $server, Configuratio $host->setSshArguments($sshOptions); } - foreach ($config->getVariables() as $key => $value) { - $this->log->debug( - sprintf('Setting var "%s" to %s for stage "%s"', $key, json_encode($value), $stage->getName()) - ); - $host->set($key, $value); - } - foreach ($config->getVariables('deploy') as $key => $value) { - $this->log->debug( - sprintf('Setting var "%s" to %s for stage "%s"', $key, json_encode($value), $stage->getName()) - ); - $host->set($key, $value); + $variableSections = [ + 'all', + 'all:' . $stage->getName(), + 'deploy', + 'deploy:' . $stage->getName(), + ]; + + foreach ($variableSections as $section) { + foreach ($config->getVariables($section) as $key => $value) { + $this->log->debug( + sprintf('Setting var "%s" to %s for stage "%s"', $key, json_encode($value), $section) + ); + $host->set($key, $value); + } } } @@ -265,7 +268,7 @@ private function maybeConfigureBrancherServer(Server $server, bool $reuseBranche /** * Initialize build stage */ - private function initializeBuildStage(Configuration $config): void + private function initializeBuildStage(Configuration $config, string $stage): void { $host = localhost('build'); $host->set('labels', ['stage' => 'build']); @@ -273,18 +276,20 @@ private function initializeBuildStage(Configuration $config): void $host->set('deploy_path', '.'); $host->set('release_or_current_path', '.'); - foreach ($config->getVariables() as $key => $value) { - $this->log->debug( - sprintf('Setting var "%s" to %s for stage "build"', $key, json_encode($value)) - ); - $host->set($key, $value); - } - - foreach ($config->getVariables('build') as $key => $value) { - $this->log->debug( - sprintf('Setting var "%s" to %s for stage "build"', $key, json_encode($value)) - ); - $host->set($key, $value); + $variableSections = [ + 'all', + 'all:' . $stage, + 'build', + 'build:' . $stage, + ]; + + foreach ($variableSections as $section) { + foreach ($config->getVariables() as $key => $value) { + $this->log->debug( + sprintf('Setting var "%s" to %s for stage "%s"', $key, json_encode($value), $section), + ); + $host->set($key, $value); + } } }