Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to fail build on drush errors #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions DrushTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class DrushTask extends Task {
private $bin = NULL;
private $uri = NULL;
private $root = NULL;
private $site_alias = NULL;
private $assume = NULL;
private $simulate = FALSE;
private $pipe = FALSE;
Expand Down Expand Up @@ -93,6 +94,10 @@ public function setRoot($str) {
$this->root = $str;
}

public function setSiteAlias($str) {
$this->site_alias = $str;
}

/**
* URI of the Drupal to use.
*/
Expand Down Expand Up @@ -198,6 +203,7 @@ public function init() {
$this->root = $this->getProject()->getProperty('drush.root');
$this->uri = $this->getProject()->getProperty('drush.uri');
$this->bin = $this->getProject()->getProperty('drush.bin');
$this->site_alias = $this->getProject()->getProperty('drush.site_alias');
}

/**
Expand All @@ -212,7 +218,13 @@ public function main() {
$option->setName('nocolor');
$this->options[] = $option;

if (!empty($this->root)) {
if (!empty($this->site_alias)) {
$param = new DrushParam();
$param->addText($this->site_alias);
$command[] = $param->getValue();
}

if (!empty($this->root) && empty($this->site_alias)) {
$option = new DrushOption();
$option->setName('root');
$option->addText($this->root);
Expand Down Expand Up @@ -265,10 +277,13 @@ public function main() {
// Execute Drush.
$this->log("Executing '$command'...");
$output = array();
exec($command, $output, $return);
exec($command . ' 2>&1', $output, $return);
// Collect Drush output for display through Phing's log.
foreach ($output as $line) {
$this->log($line);
if ($this->haltonerror && strpos($line, 'Drush command terminated abnormally due to an unrecoverable error.') !== FALSE) {
throw new BuildException("Drush command terminated abnormally due to an unrecoverable error.");
}
}
// Set value of the 'pipe' property.
if (!empty($this->return_property)) {
Expand Down