diff --git a/PHPCI/Model/Build/MercurialBuild.php b/PHPCI/Model/Build/MercurialBuild.php index 0f38940b3..c3c69c4d2 100644 --- a/PHPCI/Model/Build/MercurialBuild.php +++ b/PHPCI/Model/Build/MercurialBuild.php @@ -42,7 +42,7 @@ public function createWorkingCopy(Builder $builder, $buildPath) } if (!$success) { - $builder->logFailure('Failed to clone remote git repository.'); + $builder->logFailure('Failed to clone remote mercurial repository.'); return false; } @@ -62,7 +62,7 @@ protected function cloneByHttp(Builder $builder, $cloneTo) */ protected function cloneBySsh(Builder $builder, $cloneTo) { - $keyFile = $this->writeSshKey(); + $keyFile = $this->writeSshKey($cloneTo); // Do the git clone: $cmd = 'hg clone --ssh "ssh -i '.$keyFile.'" %s "%s"'; @@ -77,6 +77,22 @@ protected function cloneBySsh(Builder $builder, $cloneTo) return $success; } + /** + * Create an SSH key file on disk for this build. + * @param $cloneTo + * @return string + */ + protected function writeSshKey($cloneTo) + { + $keyPath = dirname($cloneTo . '/temp'); + $keyFile = $keyPath . '.key'; + // Write the contents of this project's git key to the file: + file_put_contents($keyFile, $this->getProject()->getSshPrivateKey()); + chmod($keyFile, 0600); + // Return the filename: + return $keyFile; + } + /** * Handle post-clone tasks (switching branch, etc.) * @param Builder $builder