protected function _exec($command) { $replaces = array('{build_dir}' => $this->_buildDir, '{branch}' => $this->_branch); $command = str_replace(array_keys($replaces), array_values($replaces), $command); $this->log($command); $returnProp = 'build.update.return'; $outputProp = 'build.update.output'; $obj = new ExecTask(); $obj->setProject($this->project); $obj->setCommand($command); $obj->setLogoutput(true); $obj->setReturnProperty($returnProp); $obj->setOutputProperty($outputProp); $obj->setPassthru(true); $obj->main(); }
public function main() { if (empty($this->_target)) { $message = 'Param "target" not found.'; throw new BuildException($message); } $this->_checkHost($this->_host); $msg = sprintf("Host: %s, IPs found: %s", $host, implode(' ', $this->_ips)); $this->log($msg); $msg = sprintf('Target: %s', $this->_target); $this->log($msg); $commandAr = array(); $buildDirRoot = $this->getProject()->getProperty('build.dir.root'); $commandAr[] = $buildDirRoot . '/bin/phing'; $projectBasedir = $this->getProject()->getProperty('project.basedir'); $commandAr[] = sprintf('-f %s/build.xml', $projectBasedir); $commandAr[] = $this->_target; $buildType = $this->getProject()->getProperty('build.type'); $commandAr[] = sprintf('-Dbt=%s', $buildType); $buildUser = $this->getProject()->getProperty('build.user'); if ($buildUser) { $commandAr[] = sprintf('-Dbu=%s', $buildUser); } $buildBranch = $this->getProject()->getProperty('build.branch'); if ($buildBranch) { $commandAr[] = sprintf('-Dbb=%s', $buildBranch); } foreach ($this->_ips as $ip) { $command = sprintf('ssh %s %s', $ip, implode(' ', $commandAr)); $msg = 'Run command ' . $command; $this->log($msg); $returnProp = 'remote.return'; $outputProp = 'remote.output'; $obj = new ExecTask(); $obj->setProject($this->project); $obj->setCommand($command); $obj->setLogoutput(true); $obj->setReturnProperty($returnProp); $obj->setOutputProperty($outputProp); $obj->setCheckreturn($this->_checkreturn); $obj->setPassthru(true); $obj->setLevel('info'); $obj->main(); } }