Skip to content

Commit 0067d83

Browse files
authored
Merge pull request #35 from nkatzman/privateCheckout
feat(scm-bitbucket): Support private repos in bitbucket
2 parents 5725996 + a121549 commit 0067d83

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,14 +626,21 @@ class BitbucketScm extends Scm {
626626
* @return {Promise}
627627
*/
628628
_getCheckoutCommand(config) {
629-
const checkoutUrl = `https://${config.host}/${config.org}/${config.repo}`;
629+
const checkoutUrl = `${config.host}/${config.org}/${config.repo}`;
630+
const sshCheckoutUrl = `git@${config.host}:${config.org}/${config.repo}`;
630631
const checkoutRef = config.prRef ? config.branch : config.sha;
631632
const command = [];
632633

633634
// Git clone
634635
command.push(`echo Cloning ${checkoutUrl}, on branch ${config.branch}`);
636+
command.push('if [ -n $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; ' +
637+
`then export SCM_URL=${sshCheckoutUrl}; ` +
638+
'elif [ -n $SCM_USERNAME ] && [ -n $SCM_ACCESS_TOKEN ]; ' +
639+
`then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@${checkoutUrl}; ` +
640+
`else export SCM_URL=https://${checkoutUrl}; fi`
641+
);
635642
command.push(`git clone --quiet --progress --branch ${config.branch} `
636-
+ `${checkoutUrl} $SD_SOURCE_DIR`);
643+
+ '$SCM_URL $SD_SOURCE_DIR');
637644
// Reset to Sha
638645
command.push(`echo Reset to SHA ${checkoutRef}`);
639646
command.push(`git reset --hard ${checkoutRef}`);

test/data/commands.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"name": "sd-checkout-code",
3-
"command": "echo Cloning https://hostName/orgName/repoName, on branch branchName && git clone --quiet --progress --branch branchName https://hostName/orgName/repoName $SD_SOURCE_DIR && echo Reset to SHA shaValue && git reset --hard shaValue && echo Setting user name and user email && git config user.name sd-buildbot && git config user.email dev-null@screwdriver.cd"
3+
"command": "echo Cloning hostName/orgName/repoName, on branch branchName && if [ -n $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@hostName:orgName/repoName; elif [ -n $SCM_USERNAME ] && [ -n $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@hostName/orgName/repoName; else export SCM_URL=https://hostName/orgName/repoName; fi && git clone --quiet --progress --branch branchName $SCM_URL $SD_SOURCE_DIR && echo Reset to SHA shaValue && git reset --hard shaValue && echo Setting user name and user email && git config user.name sd-buildbot && git config user.email dev-null@screwdriver.cd"
44
}

test/data/customPrCommands.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"name": "sd-checkout-code",
3-
"command": "echo Cloning https://hostName/orgName/repoName, on branch branchName && git clone --quiet --progress --branch branchName https://hostName/orgName/repoName $SD_SOURCE_DIR && echo Reset to SHA branchName && git reset --hard branchName && echo Setting user name and user email && git config user.name abcd && git config user.email dev-null@my.email.com && echo Fetching PR and merging with branchName && git fetch origin prBranch && git merge shaValue"
3+
"command": "echo Cloning hostName/orgName/repoName, on branch branchName && if [ -n $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@hostName:orgName/repoName; elif [ -n $SCM_USERNAME ] && [ -n $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@hostName/orgName/repoName; else export SCM_URL=https://hostName/orgName/repoName; fi && git clone --quiet --progress --branch branchName $SCM_URL $SD_SOURCE_DIR && echo Reset to SHA branchName && git reset --hard branchName && echo Setting user name and user email && git config user.name abcd && git config user.email dev-null@my.email.com && echo Fetching PR and merging with branchName && git fetch origin prBranch && git merge shaValue"
44
}

test/data/prCommands.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"name": "sd-checkout-code",
3-
"command": "echo Cloning https://hostName/orgName/repoName, on branch branchName && git clone --quiet --progress --branch branchName https://hostName/orgName/repoName $SD_SOURCE_DIR && echo Reset to SHA branchName && git reset --hard branchName && echo Setting user name and user email && git config user.name sd-buildbot && git config user.email dev-null@screwdriver.cd && echo Fetching PR and merging with branchName && git fetch origin prBranch && git merge shaValue"
3+
"command": "echo Cloning hostName/orgName/repoName, on branch branchName && if [ -n $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@hostName:orgName/repoName; elif [ -n $SCM_USERNAME ] && [ -n $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@hostName/orgName/repoName; else export SCM_URL=https://hostName/orgName/repoName; fi && git clone --quiet --progress --branch branchName $SCM_URL $SD_SOURCE_DIR && echo Reset to SHA branchName && git reset --hard branchName && echo Setting user name and user email && git config user.name sd-buildbot && git config user.email dev-null@screwdriver.cd && echo Fetching PR and merging with branchName && git fetch origin prBranch && git merge shaValue"
44
}

0 commit comments

Comments
 (0)