Allow passing a specific build as an input

Fixes #62.
This commit is contained in:
Eelco Dolstra 2013-11-11 21:36:26 +00:00
parent 8f104396ec
commit dd4e57fb0c
3 changed files with 20 additions and 11 deletions

View file

@ -175,14 +175,17 @@ sub nixExprPathFromParams {
sub checkInputValue { sub checkInputValue {
my ($c, $name, $type, $value) = @_; my ($c, $name, $type, $value) = @_;
$value = trim $value; $value = trim $value;
error($c, "The value $value of input $name is not a Boolean (true or false).") if error($c, "The value $value of input $name is not a Boolean (true or false).") if
$type eq "boolean" && !($value eq "true" || $value eq "false"); $type eq "boolean" && !($value eq "true" || $value eq "false");
error($c, "The value $value of input $name does not specify a Hydra evaluation. " error($c, "The value $value of input $name does not specify a Hydra evaluation. "
. "It should be either the number of a specific evaluation, the name of " . "It should be either the number of a specific evaluation, the name of "
. "a jobset (given as <project>:<jobset>), or the name of a job (<project>:<jobset>:<job>).") . "a jobset (given as <project>:<jobset>), or the name of a job (<project>:<jobset>:<job>).")
if $type eq "eval" && $value !~ /^\d+$/ if $type eq "eval" && $value !~ /^\d+$/
&& $value !~ /^$projectNameRE:$jobsetNameRE$/ && $value !~ /^$projectNameRE:$jobsetNameRE$/
&& $value !~ /^$projectNameRE:$jobsetNameRE:$jobNameRE$/; && $value !~ /^$projectNameRE:$jobsetNameRE:$jobNameRE$/;
return $value; return $value;
} }

View file

@ -36,8 +36,8 @@ sub begin :Private {
'string' => 'String value', 'string' => 'String value',
'boolean' => 'Boolean', 'boolean' => 'Boolean',
'nix' => 'Nix expression', 'nix' => 'Nix expression',
'build' => 'Build output', 'build' => 'Previous Hydra build',
'sysbuild' => 'Build output (same system)', 'sysbuild' => 'Previous Hydra build (same system)',
'eval' => 'Previous Hydra evaluation' 'eval' => 'Previous Hydra evaluation'
}; };
$_->supportedInputTypes($c->stash->{inputTypes}) foreach @{$c->hydra_plugins}; $_->supportedInputTypes($c->stash->{inputTypes}) foreach @{$c->hydra_plugins};

View file

@ -78,16 +78,22 @@ sub attrsToSQL {
sub fetchInputBuild { sub fetchInputBuild {
my ($db, $project, $jobset, $name, $value) = @_; my ($db, $project, $jobset, $name, $value) = @_;
my $prevBuild;
if ($value =~ /^\d+$/) {
$prevBuild = $db->resultset('Builds')->find({ id => int($value) });
} else {
my ($projectName, $jobsetName, $jobName, $attrs) = parseJobName($value); my ($projectName, $jobsetName, $jobName, $attrs) = parseJobName($value);
$projectName ||= $project->name; $projectName ||= $project->name;
$jobsetName ||= $jobset->name; $jobsetName ||= $jobset->name;
# Pick the most recent successful build of the specified job. # Pick the most recent successful build of the specified job.
(my $prevBuild) = $db->resultset('Builds')->search( $prevBuild = $db->resultset('Builds')->search(
{ finished => 1, project => $projectName, jobset => $jobsetName { finished => 1, project => $projectName, jobset => $jobsetName
, job => $jobName, buildStatus => 0 }, , job => $jobName, buildStatus => 0 },
{ order_by => "me.id DESC", rows => 1 { order_by => "me.id DESC", rows => 1
, where => \ attrsToSQL($attrs, "me.id") }); , where => \ attrsToSQL($attrs, "me.id") })->single;
}
return () if !defined $prevBuild || !isValidPath(getMainOutput($prevBuild)->path); return () if !defined $prevBuild || !isValidPath(getMainOutput($prevBuild)->path);