简体   繁体   中英

Installing non-public packages from Gitlab using devtools::install_git

My institution recently installed GitLab for us. I've figured out how to install R packages from the GitLab server using devtools::install_git and it works as long as the project is public.

#* When modeltable project has Public status
devtools::install_git('https://mini-me2.lerner.ccf.org/nutterb/modeltable.git')

However, if I have a package that is listed as either "Internal" or "Private," I can't install the package without some form of authentication. As of yet, I haven't figured out how to pass authentication via the URL. Does anyone have experience with downloading packages from GitLab?

#* After changing the 'modeltable' project to Private status
devtools::install_git('https://mini-me2.lerner.ccf.org/nutterb/modeltable.git')
Preparing installation of modeltable using the Git-URL: https://mini-me2.lerner.ccf.org/nutterb/modeltable.git
'/usr/bin/git'clone --depth 1 --no-hardlinks https://mini-me2.lerner.ccf.org/nutterb/modeltable.git /tmp/Rtmp5aj1cU/file24493dc03a32
Error: There seems to be a problem retrieving this Git-URL.

I'd highly recommend going the SSH route, and the below works for that. I found making the leap to SSH was easy, especially with R and RStudio. I'm using Windows in the below example. Edits from code I use in practice are in all caps.

creds = git2r::cred_ssh_key("C:\\Users\\MYSELF\\.ssh\\id_rsa.pub",
                            "C:\\Users\\MYSELF\\.ssh\\id_rsa")
devtools::install_git("git@gitlab.WORKDOMAIN.com:GITLABGROUP/PACKAGE.git",
                      credentials = creds)

Two quick additional comments:

  • git2r is imported with devtools, you shouldn't need to install it separately.
  • Also I don't think this should need mentioning, but passwords in plaintext in your script is a very bad idea.

You could try a combination of the devtools and getPass packages.

https://github.com/wrathematics/getPass

devtools::install_git(
  "https://gitlab.com/foo/bar.git", 
  credentials = git2r::cred_user_pass("uname", getPass::getPass())
)

Where uname is your Gitlab user name.

Per Ciro's comment, authenticating using

https://user:password@domain.com/user/repo.git

does the trick. So the complete call would be

devtools::install_git('https://user:password@mini-me2.lerner.ccf.org/nutterb/modeltable.git')

Please note that there may be security concerns with passing the user name and password this way. I'm not completely educated on those concerns. This works well enough for my purposes because I am authenticated on my company's network to even see the GitLab server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM