Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 888
1awuesterose Avatar asked Jun 26 '19 07:06

1awuesterose


People also ask

Where are environment variables stored GitLab?

Jobs and pipelines as environments The variables can be stored in the project/group/instance settings and be made available to jobs in pipelines.

Do I need to backup GitLab?

It is recommended to keep a copy of /etc/gitlab , or at least of /etc/gitlab/gitlab-secrets. json , in a safe place. If you ever need to restore a GitLab application backup you need to also restore gitlab-secrets. json .

What is Ci_job_token?

CI_JOB_TOKEN: A token to authenticate with certain API endpoints. The token is valid as long as the job is running.


1 Answers

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

like image 104
Iron Bishop Avatar answered Oct 27 '22 00:10

Iron Bishop