2

I am trying to install an R package from a private git repository hosted on my employer's internal Bitbucket server.

I have had success using remotes::install_git() for other projects on public servers in the past however for this specific project I need to connect to the repository via an HTTPS url and use a personal access token (PAT) to authenticate. The remotes::install_git() documentation includes an entry for adding credentials, but the documentation for this option is sparse. There is a lot of documentation for remotes::install_github(), but as this is not a github hosted repository, many of the suggestions there do not seem to work.

geetlord
  • 33
  • 1
  • 5
  • If it's an internal bitbucket server, have you tried `remotes::install_bitbucket(host=)`? It looks like you can use your personal access token as your password: https://confluence.atlassian.com/bitbucketserver/http-access-tokens-939515499.html – MrFlick Jul 14 '22 at 19:57
  • using `remotes::install_bitbucket(host=)` seems to require knowing the server's API url. That url does not seem to be readily available to users on our server. I have contacted our system admins to see if that might be an option though. – geetlord Jul 19 '22 at 11:18

1 Answers1

3

My go to :

gitcred <- git2r::cred_user_pass(username="$(USERNAME)",password="$(PAT)")
#here you can put any private repo such as devops azure or bitbucket, etc..
remotes::install_git("https://dev.azure.com/XXX", credentials = gitcred)'
  • when I follow this method I get the following error (tested on two computers with different R and git installs and configurations): Error: Failed to install 'unknown package' from Git: `cannot open URL 'https://bitbucketserver.org/scm/projectName/repoName/raw/xxxxxxxxxxxxx/DESCRIPTION'` – geetlord Jul 18 '22 at 17:00
  • To install a package you should stop at the root folder AKA "repoName" in this case I believe. And I imagine you can't share the real link to see what it looks like ? Another thing to check is if the permissions are well set for the user and it can download the repo. – David Muñoz Tord Jul 19 '22 at 07:07
  • The code I ran (with obscured URL and credentials) is as follows: ```gitcred <- git2r::cred_user_pass(username="username",password="personalAccessToken") remotes::install_git(url = "https://bitbucket.domain.org/scm/projectName/repository.git", credentials= gitcred )``` I can clone the repo using the same username and PAT as password from the git command line. – geetlord Jul 19 '22 at 11:14
  • I just tested it with bitbucket. 1) I created a "test" repository 2) I created an "App password" which I gave these permissions (https://support.blubracket.com/hc/en-us/articles/4404687343124-How-to-Generate-an-App-Password-or-Personal-Access-Token-PAT-in-Bitbucket) 3) I extracted my credentials: gitcred <- git2r::cred_user_pass(username="USER",password="PAT") 4) I install the repository from the ROOT : remotes::install_git(url = "https://bitbucket.org/mtdva411/test", credentials= gitcred ) note there is not ".git" nor "domain.org" nor "projectname.. I hope this might help. – David Muñoz Tord Jul 19 '22 at 11:50
  • 1
    I finally got your method to work perfectly as described. My git2r library seems to have been broken. Once I updated it, everything worked perfectly. – geetlord Jul 20 '22 at 11:41