Sunday, April 10, 2022

[SOLVED] Get all files from gitlab snippets using curl

Issue

Is there a way to get all files embedded in gitlab snippets using curl command?

Using the following command I only get the first file.

curl -O "https://gitlab.com/-/snippets/2264390/raw"

Since the snippet gathers 3 files I would like to download them all.


Solution

Use the snippets API to get the list of all the files and URLs.

https://gitlab.com/api/v4/snippets/2264390

SNIPPET_ID=2264390
curl "https://gitlab.com/api/v4/snippets/$SNIPPET_ID" | jq -r .files[].raw_url
https://gitlab.com/-/snippets/2264390/raw/main/grafana.service
https://gitlab.com/-/snippets/2264390/raw/main/install-grafana-loki-promtail.sh
https://gitlab.com/-/snippets/2264390/raw/main/loki-config.yaml
https://gitlab.com/-/snippets/2264390/raw/main/loki.service
https://gitlab.com/-/snippets/2264390/raw/main/promtail-config.yaml
https://gitlab.com/-/snippets/2264390/raw/main/promtail.service

You could pipe that output to xargs and curl them as well, if you wanted.

If you were open to using something other than curl snippets work mostly like any other repository and can be cloned with HTTPS/SSH.

git clone https://gitlab.com/snippets/2264390


Answered By - sytech
Answer Checked By - Gilberto Lyons (WPSolving Admin)