首页 > 解决方案 > 如何使用 DEPLOY_TOKEN 从 Gitlab 私有存储库安装 R 包?

问题描述

首先,一个工作命令:

使用 GITLAB_PAT 变量,在 .Renviron 文件中设置

cred <- git2r::cred_token( token = 'GITLAB_PAT' );

remotes::install_gitlab('myuser/myproject',
                        credentials = cred ,upgrade = FALSE )

安装工程!但允许访问 myuser 的所有私有包。

使用来自 envvar GITLAB_PAT 的 GitLab PAT

Downloading GitLab repo myuser/myproject@master

from URL https://gitlab.com/api/v4/projects/12345678/repository/archive.tar.gz?sha=master

√  checking for file 'C:\Users\myuser\AppData\Local\Temp\RtmpCMKBuc\remotes7e0820dc515b\myproject-master-b31c5baa8f1d2d4967b00b739216cbb9b50d74b1/DESCRIPTION' (2.8s)
-  preparing 'myproject': (526ms)
√  checking DESCRIPTION meta-information ... 
-  checking for LF line-endings in source and make files and shell scripts
-  checking for empty or unneeded directories
-  building 'myproject_0.1.0.tar.gz'
...

** testing if installed package keeps a record of temporary installation path

* DONE (myproject)

其次,我的非工作尝试使用 DEPLOY_TOKEN:

使用在 .Renviron 文件中设置的 DEPLOY_TOKEN 仅对包含包的 repo 具有读取权限

cred <- git2r::cred_token( token = 'MYPROJECT_TOKEN' );

remotes::install_gitlab('myuser/myproject',
                        credentials = cred ,upgrade = FALSE )

-> 消息说使用 Gitlab PAT 授予访问权限,这不是我想要的。

使用来自 envvar GITLAB_PAT 的 GitLab PAT

Skipping install of 'myproject' from a gitlab remote, the SHA1 (b31c5bac) has not changed since last install.

Use `force = TRUE` to force installation

总之,我可以使用 DEPLOY_TOKEN 从 Gitlab 上的私人项目安装 R 包吗?

标签: rgitlab-ci

解决方案


我在组部署令牌上找到了有用的视频https://www.youtube.com/embed/8kxTJvaD9ks?rel=0

这给了int:

git clone https://gitlab+deploy-token-157011:-vz-oxsbL2y_ffdZoedq@gitlab.com/myuser/myproject.git

有了这个方向,这行得通:(摘自.gitlab-ci.yml)

`- R -e "devtools::install_git(paste0('https://',Sys.getenv('DEPLOY_USERNAME'),":", 
                         Sys.getenv('DEPLOY_TOKEN'),
                         '@gitlab.com/myuser/myproject.git"'), upgrade = FALSE)"`

带有 gitlab 变量

DEPLOY_USERNAME=gitlab+deploy-token-157011 和 DEPLOY_TOKEN=-vz-oxsbL2y_ffdZoedq


推荐阅读