Last active
June 25, 2024 11:52
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks :)