mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Added build.id
variable and other improvements / fixes
Summary: This adds a `build.id` variable, cleans up the naming convention of other variables and also fixes an issue in the remote command to read the buffers after the command finishes. Test Plan: Ran a build with `/bin/echo ${build.id}` and saw the build ID come through. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley CC: Korvin, epriestley, aran Maniphest Tasks: T1049 Differential Revision: https://secure.phabricator.com/D7540
This commit is contained in:
parent
197e9b6f49
commit
3eaac9eda9
2 changed files with 33 additions and 20 deletions
|
@ -31,14 +31,14 @@ final class RemoteCommandBuildStepImplementation
|
||||||
$variables = $this->retrieveVariablesFromBuild($build);
|
$variables = $this->retrieveVariablesFromBuild($build);
|
||||||
$command = $settings['command'];
|
$command = $settings['command'];
|
||||||
preg_match_all(
|
preg_match_all(
|
||||||
"/\\\$\\{(?P<name>[a-z]+)\\}/",
|
"/\\\$\\{(?P<name>[a-z\.]+)\\}/",
|
||||||
$command,
|
$command,
|
||||||
$matches);
|
$matches);
|
||||||
foreach ($matches["name"] as $match) {
|
foreach ($matches["name"] as $match) {
|
||||||
$parameters[] = idx($variables, $match, "");
|
$parameters[] = idx($variables, $match, "");
|
||||||
}
|
}
|
||||||
$command = str_replace("%", "%%", $command);
|
$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 = vcsprintf(
|
||||||
$command,
|
$command,
|
||||||
|
@ -90,6 +90,12 @@ final class RemoteCommandBuildStepImplementation
|
||||||
// Get the return value so we can log that as well.
|
// Get the return value so we can log that as well.
|
||||||
list($err) = $future->resolve();
|
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_stdout->finalize($start_stdout);
|
||||||
$log_stderr->finalize($start_stderr);
|
$log_stderr->finalize($start_stderr);
|
||||||
|
|
||||||
|
|
|
@ -4,29 +4,31 @@ abstract class VariableBuildStepImplementation extends BuildStepImplementation {
|
||||||
|
|
||||||
public function retrieveVariablesFromBuild(HarbormasterBuild $build) {
|
public function retrieveVariablesFromBuild(HarbormasterBuild $build) {
|
||||||
$results = array(
|
$results = array(
|
||||||
'revision' => null,
|
'buildable.revision' => null,
|
||||||
'commit' => null,
|
'buildable.commit' => null,
|
||||||
'repository' => null,
|
'repository.callsign' => null,
|
||||||
'vcs' => null,
|
'repository.vcs' => null,
|
||||||
'uri' => null,
|
'repository.uri' => null,
|
||||||
'timestamp' => null);
|
'step.timestamp' => null,
|
||||||
|
'build.id' => null);
|
||||||
|
|
||||||
$buildable = $build->getBuildable();
|
$buildable = $build->getBuildable();
|
||||||
$object = $buildable->getBuildableObject();
|
$object = $buildable->getBuildableObject();
|
||||||
|
|
||||||
$repo = null;
|
$repo = null;
|
||||||
if ($object instanceof DifferentialRevision) {
|
if ($object instanceof DifferentialRevision) {
|
||||||
$results['revision'] = $object->getID();
|
$results['buildable.revision'] = $object->getID();
|
||||||
$repo = $object->getRepository();
|
$repo = $object->getRepository();
|
||||||
} else if ($object instanceof PhabricatorRepositoryCommit) {
|
} else if ($object instanceof PhabricatorRepositoryCommit) {
|
||||||
$results['commit'] = $object->getCommitIdentifier();
|
$results['buildable.commit'] = $object->getCommitIdentifier();
|
||||||
$repo = $object->getRepository();
|
$repo = $object->getRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
$results['repository'] = $repo->getCallsign();
|
$results['repository.callsign'] = $repo->getCallsign();
|
||||||
$results['vcs'] = $repo->getVersionControlSystem();
|
$results['repository.vcs'] = $repo->getVersionControlSystem();
|
||||||
$results['uri'] = $repo->getPublicRemoteURI();
|
$results['repository.uri'] = $repo->getPublicRemoteURI();
|
||||||
$results['timestamp'] = time();
|
$results['step.timestamp'] = time();
|
||||||
|
$results['build.id'] = $build->getID();
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
@ -44,12 +46,17 @@ abstract class VariableBuildStepImplementation extends BuildStepImplementation {
|
||||||
|
|
||||||
public function getAvailableVariables() {
|
public function getAvailableVariables() {
|
||||||
return array(
|
return array(
|
||||||
'revision' => pht('The differential revision ID, if applicable.'),
|
'buildable.revision' =>
|
||||||
'commit' => pht('The commit identifier, if applicable.'),
|
pht('The differential revision ID, if applicable.'),
|
||||||
'repository' => pht('The callsign of the repository in Phabricator.'),
|
'buildable.commit' => pht('The commit identifier, if applicable.'),
|
||||||
'vcs' => pht('The version control system, either "svn", "hg" or "git".'),
|
'repository.callsign' =>
|
||||||
'uri' => pht('The URI to clone or checkout the repository from.'),
|
pht('The callsign of the repository in Phabricator.'),
|
||||||
'timestamp' => pht('The current UNIX timestamp.'));
|
'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() {
|
public function getSettingRemarkupInstructions() {
|
||||||
|
|
Loading…
Reference in a new issue