public function environment()
 {
     // Load and parse travis file
     $travis_file = $this->buildVars['DCI_TravisFile'];
     $this->output->writeln("<comment>Loading test build parameters from travis file: </comment><info>{$travis_file}</info>");
     $build = new JobDefinition();
     $directory = trim($this->workingDirectory);
     // Ensure directory ends in a /
     if ($directory[strlen($directory) - 1] != '/') {
         $directory = $directory . "/";
     }
     $result = $build->load($directory . $travis_file);
     if ($result == -1) {
         // Error loading definition file.
         $this->output->writeln("<error>FAILED:</error> <info>Unable to parse travis file.</info>");
         // TODO: Robust error handling
         return -1;
     }
     $travis = $build->getParameters();
     // Store the parsed contents so we can reference them in later build steps
     $this->travis_parsed = $travis;
     $namespace = $this->namespace;
     $command = implode(' ', $this->commands);
     // Evaluate the parsed travis file
     $language = !empty($travis['language']) ? $travis['language'] : '';
     $language_versions = !empty($travis[$language]) ? $travis[$language] : array();
     $services = !empty($travis['services']) ? $travis['services'] : array();
     // TODO: Add Fast Fail logic
     // Get the permutations
     foreach ($language_versions as $language_version) {
         $this->output->writeln("<info>### Building permutation <options=bold>'{$language}{$language_version}'</options=bold> ###</info>");
         $permutation = new Permutation();
         $permutation->setNamespace($namespace);
         $permutation->setLanguage($language . ':' . $language_version);
         $permutation->setCommand($command);
         if (!empty($this->buildVars['DCI_Privileged'])) {
             $permutation->setPrivileged(true);
         }
         $permutation->addServices($services);
         // Print.
         $lines = $permutation->build();
         foreach ($lines as $line) {
             $this->output->writeln($line);
             if (!empty($this->script)) {
                 $this->script .= " && ";
             }
             $this->script .= $line;
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run(JobInterface $job, $data = NULL)
 {
     // Get and parse test definitions
     // DrupalCI jobs are controlled via a hierarchy of configuration settings, which define the behaviour of the platform while running DrupalCI jobs.  This hierarchy is defined as follows, which each level overriding the previous:
     // 1. Out-of-the-box DrupalCI defaults
     // 2. Local overrides defined in ~/.drupalci/config
     // 3. 'DCI_' namespaced environment variable overrides
     // 4. Test-specific overrides passed inside a DrupalCI test definition (e.g. .drupalci.yml)
     // 5. Custom overrides located inside a test definition defined via the $source variable when calling this function.
     $confighelper = new ConfigHelper();
     // Load job defaults
     $platform_args = $job->getPlatformDefaults();
     $default_args = $job->getDefaultArguments();
     if (!empty($default_args)) {
         $job->getOutput()->writeln("<comment>Loading build variables for this job type.</comment>");
     }
     // Load DrupalCI local config overrides
     $local_args = $confighelper->getCurrentConfigSetParsed();
     if (!empty($local_args)) {
         $job->getOutput()->writeln("<comment>Loading build variables from DrupalCI local config overrides.</comment>");
     }
     // Load "DCI_ namespaced" environment variable overrides
     $environment_args = $confighelper->getCurrentEnvVars();
     if (!empty($environment_args)) {
         $job->getOutput()->writeln("<comment>Loading build variables from namespaced environment variable overrides.</comment>");
     }
     // Load command line arguments
     // TODO: Routine for loading command line arguments.
     // TODO: How do we pull arguments off the drupalci command, when in a job class?
     // $cli_args = $somehelper->loadCLIargs();
     $cli_args = array();
     if (!empty($cli_args)) {
         $job->getOutput()->writeln("<comment>Loading test parameters from command line arguments.</comment>");
     }
     // Create temporary config array to use in determining the definition file source
     $config = $cli_args + $environment_args + $local_args + $default_args + $platform_args;
     // Load any build vars defined in the job definition file
     // Retrieve test definition file
     if (isset($source)) {
         $config['explicit_source'] = $source;
     }
     $definition_file = $this->getDefinitionFile($config);
     $definition_args = array();
     // Load test definition file
     if (!empty($definition_file)) {
         $job->getOutput()->writeln("<comment>Loading test parameters from build file: </comment><info>{$definition_file}</info>");
         $jobdef = new JobDefinition();
         $result = $jobdef->load($definition_file);
         if ($result == -1) {
             // Error loading definition file.
             $job->errorOutput("Failed", "Unable to parse build file.");
             // TODO: Robust error handling
             return;
         }
         $job_definition = $jobdef->getParameters();
         if (empty($job_definition)) {
             $job_definition = array();
             $definition_args = array();
         } else {
             $definition_args = !empty($job_definition['build_vars']) ? $job_definition['build_vars'] : array();
         }
         $job->setDefinition($job_definition);
     }
     $config = $cli_args + $definition_args + $environment_args + $local_args + $default_args + $platform_args;
     // Set initial build variables
     $buildvars = $job->getBuildVars();
     $job->setBuildVars($buildvars + $config);
     // Map relevant build variables into the job definition array
     // $this->buildvarsToDefinition($job);
     return;
 }