简体   繁体   中英

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. All these variables are used during our CI/CD pipeline and are crucial for our production environment.

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 . 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).

You can use the API in order to query all variables. 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

You can easily do that via API. I tested it on 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, ""'

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