Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/harbormaster/step/RemoteCommandBuildStepImplementation.php b/src/applications/harbormaster/step/RemoteCommandBuildStepImplementation.php
index a84ca21635..ce0e85fc9d 100644
--- a/src/applications/harbormaster/step/RemoteCommandBuildStepImplementation.php
+++ b/src/applications/harbormaster/step/RemoteCommandBuildStepImplementation.php
@@ -1,157 +1,163 @@
<?php
final class RemoteCommandBuildStepImplementation
extends VariableBuildStepImplementation {
public function getName() {
return pht('Run Remote Command');
}
public function getGenericDescription() {
return pht('Run a command on another machine.');
}
public function getDescription() {
$settings = $this->getSettings();
return pht(
'Run \'%s\' on \'%s\'.',
$settings['command'],
$settings['sshhost']);
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildStep $build_step) {
$settings = $this->getSettings();
$parameters = array();
$matches = array();
$variables = $this->retrieveVariablesFromBuild($build);
$command = $settings['command'];
preg_match_all(
- "/\\\$\\{(?P<name>[a-z]+)\\}/",
+ "/\\\$\\{(?P<name>[a-z\.]+)\\}/",
$command,
$matches);
foreach ($matches["name"] as $match) {
$parameters[] = idx($variables, $match, "");
}
$command = str_replace("%", "%%", $command);
- $command = preg_replace("/\\\$\\{(?P<name>[a-z]+)\\}/", "%s", $command);
+ $command = preg_replace("/\\\$\\{(?P<name>[a-z\.]+)\\}/", "%s", $command);
$command = vcsprintf(
$command,
$parameters);
$future = null;
if (empty($settings['sshkey'])) {
$future = new ExecFuture(
'ssh -o "StrictHostKeyChecking no" -p %s %s %s',
$settings['sshport'],
$settings['sshuser'].'@'.$settings['sshhost'],
$command);
} else {
$future = new ExecFuture(
'ssh -o "StrictHostKeyChecking no" -p %s -i %s %s %s',
$settings['sshport'],
$settings['sshkey'],
$settings['sshuser'].'@'.$settings['sshhost'],
$command);
}
$log_stdout = $build->createLog($build_step, "remote", "stdout");
$log_stderr = $build->createLog($build_step, "remote", "stderr");
$start_stdout = $log_stdout->start();
$start_stderr = $log_stderr->start();
// Read the next amount of available output every second.
while (!$future->isReady()) {
list($stdout, $stderr) = $future->read();
$log_stdout->append($stdout);
$log_stderr->append($stderr);
$future->discardBuffers();
// Check to see if we have moved from a "Building" status. This
// can occur if the user cancels the build, in which case we want
// to terminate whatever we're doing and return as quickly as possible.
if ($build->checkForCancellation()) {
$log_stdout->finalize($start_stdout);
$log_stderr->finalize($start_stderr);
$future->resolveKill();
return;
}
// Wait one second before querying for more data.
sleep(1);
}
// Get the return value so we can log that as well.
list($err) = $future->resolve();
+ // Retrieve the last few bits of information.
+ list($stdout, $stderr) = $future->read();
+ $log_stdout->append($stdout);
+ $log_stderr->append($stderr);
+ $future->discardBuffers();
+
$log_stdout->finalize($start_stdout);
$log_stderr->finalize($start_stderr);
if ($err) {
$build->setBuildStatus(HarbormasterBuild::STATUS_FAILED);
}
}
public function validateSettings() {
$settings = $this->getSettings();
if ($settings['command'] === null || !is_string($settings['command'])) {
return false;
}
if ($settings['sshhost'] === null || !is_string($settings['sshhost'])) {
return false;
}
if ($settings['sshuser'] === null || !is_string($settings['sshuser'])) {
return false;
}
if ($settings['sshkey'] === null || !is_string($settings['sshkey'])) {
return false;
}
if ($settings['sshport'] === null || !is_int($settings['sshport']) ||
$settings['sshport'] <= 0 || $settings['sshport'] >= 65536) {
return false;
}
$whitelist = PhabricatorEnv::getEnvConfig(
'harbormaster.temporary.hosts.whitelist');
if (!in_array($settings['sshhost'], $whitelist)) {
return false;
}
return true;
}
public function getSettingDefinitions() {
return array(
'command' => array(
'name' => 'Command',
'description' => 'The command to execute on the remote machine.',
'type' => BuildStepImplementation::SETTING_TYPE_STRING),
'sshhost' => array(
'name' => 'SSH Host',
'description' => 'The SSH host that the command will be run on.',
'type' => BuildStepImplementation::SETTING_TYPE_STRING),
'sshport' => array(
'name' => 'SSH Port',
'description' => 'The SSH port to connect to.',
'type' => BuildStepImplementation::SETTING_TYPE_INTEGER,
'default' => 22), // TODO: 'default' doesn't do anything yet..
'sshuser' => array(
'name' => 'SSH Username',
'description' => 'The SSH username to use.',
'type' => BuildStepImplementation::SETTING_TYPE_STRING),
'sshkey' => array(
'name' => 'SSH Identity File',
'description' =>
'The path to the SSH identity file (private key) '.
'on the local web server.',
'type' => BuildStepImplementation::SETTING_TYPE_STRING));
}
}
diff --git a/src/applications/harbormaster/step/VariableBuildStepImplementation.php b/src/applications/harbormaster/step/VariableBuildStepImplementation.php
index 7f91518282..26054db07c 100644
--- a/src/applications/harbormaster/step/VariableBuildStepImplementation.php
+++ b/src/applications/harbormaster/step/VariableBuildStepImplementation.php
@@ -1,67 +1,74 @@
<?php
abstract class VariableBuildStepImplementation extends BuildStepImplementation {
public function retrieveVariablesFromBuild(HarbormasterBuild $build) {
$results = array(
- 'revision' => null,
- 'commit' => null,
- 'repository' => null,
- 'vcs' => null,
- 'uri' => null,
- 'timestamp' => null);
+ 'buildable.revision' => null,
+ 'buildable.commit' => null,
+ 'repository.callsign' => null,
+ 'repository.vcs' => null,
+ 'repository.uri' => null,
+ 'step.timestamp' => null,
+ 'build.id' => null);
$buildable = $build->getBuildable();
$object = $buildable->getBuildableObject();
$repo = null;
if ($object instanceof DifferentialRevision) {
- $results['revision'] = $object->getID();
+ $results['buildable.revision'] = $object->getID();
$repo = $object->getRepository();
} else if ($object instanceof PhabricatorRepositoryCommit) {
- $results['commit'] = $object->getCommitIdentifier();
+ $results['buildable.commit'] = $object->getCommitIdentifier();
$repo = $object->getRepository();
}
- $results['repository'] = $repo->getCallsign();
- $results['vcs'] = $repo->getVersionControlSystem();
- $results['uri'] = $repo->getPublicRemoteURI();
- $results['timestamp'] = time();
+ $results['repository.callsign'] = $repo->getCallsign();
+ $results['repository.vcs'] = $repo->getVersionControlSystem();
+ $results['repository.uri'] = $repo->getPublicRemoteURI();
+ $results['step.timestamp'] = time();
+ $results['build.id'] = $build->getID();
return $results;
}
public function mergeVariables(HarbormasterBuild $build, $string) {
$variables = $this->retrieveVariablesFromBuild($build);
foreach ($variables as $name => $value) {
if ($value === null) {
$value = '';
}
$string = str_replace('${'.$name.'}', $value, $string);
}
return $string;
}
public function getAvailableVariables() {
return array(
- 'revision' => pht('The differential revision ID, if applicable.'),
- 'commit' => pht('The commit identifier, if applicable.'),
- 'repository' => pht('The callsign of the repository in Phabricator.'),
- 'vcs' => pht('The version control system, either "svn", "hg" or "git".'),
- 'uri' => pht('The URI to clone or checkout the repository from.'),
- 'timestamp' => pht('The current UNIX timestamp.'));
+ 'buildable.revision' =>
+ pht('The differential revision ID, if applicable.'),
+ 'buildable.commit' => pht('The commit identifier, if applicable.'),
+ 'repository.callsign' =>
+ pht('The callsign of the repository in Phabricator.'),
+ 'repository.vcs' =>
+ pht('The version control system, either "svn", "hg" or "git".'),
+ 'repository.uri' =>
+ pht('The URI to clone or checkout the repository from.'),
+ 'step.timestamp' => pht('The current UNIX timestamp.'),
+ 'build.id' => pht('The ID of the current build.'));
}
public function getSettingRemarkupInstructions() {
$text = '';
$text .= pht('The following variables are available: ')."\n";
$text .= "\n";
foreach ($this->getAvailableVariables() as $name => $desc) {
$text .= ' - `'.$name.'`: '.$desc."\n";
}
$text .= "\n";
$text .= "Use `\${name}` to merge a variable into a setting.";
return $text;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Jul 28, 6:41 AM (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
186452
Default Alt Text
(9 KB)

Event Timeline