/** * {@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; }
protected function create_local_checkout_dir(JobInterface $job) { $arguments = $job->getBuildVars(); $directory = $arguments['DCI_CheckoutDir']; $tempdir = sys_get_temp_dir(); // Prefix the system temp dir on the DCI_CheckoutDir variable if needed if (strpos($directory, $tempdir) !== 0) { // If not, prefix the system temp directory on the variable. if ($directory[0] != "/") { $directory = "/" . $directory; } $arguments['DCI_CheckoutDir'] = $tempdir . $directory; $job->setBuildVars($arguments); } // Check if the DCI_CheckoutDir exists within the /tmp directory, or create it if not $path = realpath($arguments['DCI_CheckoutDir']); if ($path !== FALSE) { // Directory exists. Check that we're still in /tmp if (!$this->validate_checkout_dir($job)) { // Something bad happened. Attempt to transverse out of the /tmp dir, perhaps? $job->errorOutput("Error", "Detected an invalid local checkout directory. The checkout directory must reside somewhere within the system temporary file directory."); return; } else { // Directory is within the system temp dir. $job->getOutput()->writeln("<comment>Found existing local checkout directory <info>{$path}</info></comment>"); return; } } elseif ($path === FALSE) { // Directory doesn't exist, so create it. $directory = $arguments['DCI_CheckoutDir']; mkdir($directory, 0777, true); $job->getOutput()->writeln("<comment>Checkout Directory created at <info>{$directory}</info>"); // Ensure we are under the system temp dir if (!$this->validate_checkout_dir($job)) { // Something bad happened. Attempt to transverse out of the /tmp dir, perhaps? $job->errorOutput("Error", "DCI_CheckoutDir must reside somewhere within the system temporary file directory. You may wish to manually remove the directory created above."); return; } } }