Skip to content

Instantly share code, notes, and snippets.

@JamesCullum
Last active March 19, 2024 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesCullum/8af9da6067840f70a3ec9260cb38d972 to your computer and use it in GitHub Desktop.
Save JamesCullum/8af9da6067840f70a3ec9260cb38d972 to your computer and use it in GitHub Desktop.
Import all CI/CD variables from Gitlab API and add them to the bash shell for further usage. Made for Ubuntu. Can be combined neatly with Cloud IDEs such as goormIDE to always load the project CI variables into the editor.
#!/bin/bash
# works with /bin/sh as well
# requires sudo permission
apt-get -y install jq
curl --header "PRIVATE-TOKEN: <token>" "https://gitlab.com/api/v4/projects/1/variables" |
jq -c '.[]' |
while IFS=$"\n" read -r c; do
key=$(echo "$c" | jq -r '.key')
val=$(echo "$c" | jq -r '.value')
type=$(echo "$c" | jq -r '.variable_type')
if [[ "$type" == "file" ]]
then
echo "$val" > "/root/$key"
echo "export $key=/root/$key" >> ~/.bashrc
else
echo "export $key=$val" >> ~/.bashrc
fi
done
source ~/.bashrc
@eidmantas
Copy link

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment