简体   繁体   English

如何备份/导出 Gitlab CI 环境变量?

[英]How to backup/export Gitlab CI environment variables?

We have a continuously growing collection of Gitlab CI variables (around 40-50) in our current project.在我们当前的项目中,我们有一个不断增长的 Gitlab CI 变量集合(大约 40-50)。 All these variables are used during our CI/CD pipeline and are crucial for our production environment.所有这些变量都在我们的 CI/CD 管道中使用,对我们的生产环境至关重要。

I want to generate backups in regular intervals in case someone messes with these variables.我想定期生成备份,以防有人弄乱这些变量。

Unfortunately, I do not see any options to export the variables in Project -> Settings -> CI / CD -> Environment variables .不幸的是,我在Project -> Settings -> CI / CD -> Environment variables中看不到任何导出变量的选项。 All I can do is viewing / editing / deleting the variables.我所能做的就是查看/编辑/删除变量。

Is there maybe a hidden export function for these variables?这些变量是否有隐藏的导出功能? We are self-hosting our Gitlab instance (GitLab Community Edition 11.8.1).我们正在自托管我们的 Gitlab 实例(GitLab 社区版 11.8.1)。

You can use the API in order to query all variables.您可以使用 API 来查询所有变量。 For example:例如:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/variables/TEST_VARIABLE_1"

See: https://docs.gitlab.com/ce/api/project_level_variables.html#show-variable-details请参阅: https ://docs.gitlab.com/ce/api/project_level_variables.html#show-variable-details

You can easily do that via API.您可以通过 API 轻松做到这一点。 I tested it on 14.8 .我在14.8上对其进行了测试。

# Instance-level CI/CD variables
curl --header "PRIVATE-TOKEN: your-priv-token" "https://gitlab.example.com/api/v4/admin/ci/variables" | jq -r '.[] | .key, .value, ""'

# Group-level Variables
curl --header "PRIVATE-TOKEN: your-priv-token" "https://gitlab.example.com/api/v4/groups/1/variables" | jq -r '.[] | .key, .value, ""'

# Project-level Variables
curl --header "PRIVATE-TOKEN: your-priv-token" "https://gitlab.example.com/api/v4/projects/1/variables" | jq -r '.[] | .key, .value, ""'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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