Skip to content

Instantly share code, notes, and snippets.

@JamesCullum
Last active June 25, 2024 11:52
Show Gist options
  • 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
@netmanbworker
Copy link

Thank you James!

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