Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mercurial build by ssh connection #1350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions PHPCI/Model/Build/MercurialBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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"';
Expand All @@ -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
Expand Down