diff --git a/src/DrupalCI/Plugin/BuildSteps/setup/Patch.php b/src/DrupalCI/Plugin/BuildSteps/setup/Patch.php index 12815c1..b56e5b4 100644 --- a/src/DrupalCI/Plugin/BuildSteps/setup/Patch.php +++ b/src/DrupalCI/Plugin/BuildSteps/setup/Patch.php @@ -41,14 +41,37 @@ class Patch extends SetupBase { $job->errorOutput("Error", "The patch directory $directory is invalid."); return; } - $cmd = "cd $directory && git apply -v -p1 $patchfile && cd -"; + $cmd = "cd $directory && git apply -v -p1 $patchfile 2>&1 && cd -"; - $this->exec($cmd, $cmdoutput, $result); + exec($cmd, $cmdoutput, $result); if ($result !== 0) { // The command threw an error. $job->errorOutput("Patch failed", "The patch attempt returned an error."); Output::writeLn($cmdoutput); // TODO: Pass on the actual return value for the patch attempt + // Save an xmlfile to the jenkins artifact directory. + // find jenkins artifact dir + // + $source_dir = $job->getBuildVar('DCI_CheckoutDir'); + // TODO: Temporary hack. Strip /checkout off the directory + $artifact_dir = preg_replace('#/checkout$#', '', $source_dir); + + // Set up output directory (inside working directory) + $output_directory = $artifact_dir . DIRECTORY_SEPARATOR . 'artifacts' . DIRECTORY_SEPARATOR . $job->getBuildVar('DCI_JunitXml'); + + mkdir($output_directory, 0777, TRUE); + $output = preg_replace('/[^\x{0009}\x{000A}\x{000D}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u', '�', implode("\n", $cmdoutput)); + + $xml_error = ' + + + + Patch failed to apply + + + '; + file_put_contents($output_directory . "/patchfailure.xml", $xml_error); + return; } Output::writeLn("Patch $patchfile applied to directory $directory");