/**
* Start a pipeline
*
* @param array $data
* @param DeployForm $form
* @param bool $isDryRun
* @return \SS_HTTPResponse
*/
protected function beginPipeline($data, DeployForm $form, $isDryRun = false)
{
$buildName = $form->getSelectedBuild($data);
// Performs canView permission check by limiting visible projects
$project = $this->getCurrentProject();
if (!$project) {
return $this->project404Response();
}
// Performs canView permission check by limiting visible projects
$environment = $this->getCurrentEnvironment($project);
if (!$environment) {
return $this->environment404Response();
}
if (!$environment->DryRunEnabled && $isDryRun) {
return new SS_HTTPResponse("Dry-run for pipelines is not enabled for this environment", 404);
}
// Initiate the pipeline
$sha = $project->DNBuildList()->byName($buildName);
$pipeline = Pipeline::create();
$pipeline->DryRun = $isDryRun;
$pipeline->EnvironmentID = $environment->ID;
$pipeline->AuthorID = Member::currentUserID();
$pipeline->SHA = $sha->FullName();
// Record build at time of execution
if ($currentBuild = $environment->CurrentBuild()) {
$pipeline->PreviousDeploymentID = $currentBuild->ID;
}
$pipeline->start();
// start() will call write(), so no need to do it here as well.
return $this->redirect($environment->Link());
}