无法使用命令行从gitlab下载文件

问题描述

我有一个gitlab的内部部署:https://gitlab.corp.mycompany.com/project/account/config-file/repo/blob/long_alphanumeric_numer/my_wanted_file

我想通过命令行下载“ my_wanted_file”。它包含配置内容

我到目前为止已经尝试过:

curl -o https://gitlab.corp.mycompany.com/project/account/configfile/repo/blob/master/my_wanted_file

wget https://gitlab.corp.mycompany.com/project/account/configfile/repo/blob/master/my_wanted_file

然后我单击“永久链接”,然后尝试以下操作:

curl -OL https://gitlab.corp.mycompany.com/project/account/configfile/repo/blob/long_alphanumeric_numer/my_wanted_file

wget https://gitlab.corp.mycompany.com/project/account/configfile/repo/blob/long_alphanumeric_numer/my_wanted_file```

curl 'Private-Token: my_private_token' https://gitlab.corp.mycompany.com/project/account/configfile/repo/blob/long_alphanumeric_numer/my_wanted_file

使用curl --header'Private-Token:my_private_token'加上url,返回以下消息:

<html><body>You are being 
<a href="https://gitlab.corp.my_company.com/users/sign_in">redirected</a>.</body></html>

在所有情况下,我的确得到了一个带有Java脚本内容的怪异文件,但从未获得my_wanted_file当前在gitlab中显示配置文件内容

我认为让大家知道我正在通过okta连接到此私有gitlab部署很重要。不知道这是否在中间引入了一些噪音,因此需要提供不同的命令。

可以请教吗?

解决方法

在这种情况下,最好使用Gitlab API,特别是Repository File API从存储库获取文件:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.corp.mycompany.com/api/v4/projects/<project_id>/repository/files/my_wanted_file?ref=master"

在这些instructions之后创建您的个人令牌。