Whenever I have to setup private.yml when working setting up a grove cluster repository locally, it’s annoying to have to manually copy CI/CD variables into the file. I decided to automate it a bit.
First of all, we can get variables using GitLab’s API (gitlab docs):
curl --header "PRIVATE-TOKEN: <your access token with api access>" "https://gitlab.com/api/v4/projects/<project_id>/variables"
Then you would want to parse JSON. jq is a great command for that, and you can get all the variables in the form <name>: <value> you can do the following (assumes you’ve saved the output of the previous command to ci-cd-variables.json):