de:sysadmin:tools:gitlab-ci-variable-export

gitlab CI environment exportieren (privat)

save gitlab variables

#!/usr/bin/bash
 
# fetch all variables of readable projects
 
BASEURL="https://gitlab.example.org/api/v4/"
 
GITLABTOKEN=$( cat $HOME/private/gitlab-token )
 
if [ -z $GITLABTOKEN ]; then
    echo 'please set the environment variable GITLABTOKEN'
    exit 10
fi
 
TIMESTAMP=$( date -u +%Y-%m-%d )
EXPORTPATH=$HOME/private/gitlab-variables/$TIMESTAMP
mkdir -p $EXPORTPATH
 
CURL="curl -s --header PRIVATE-TOKEN:$GITLABTOKEN"
 
$CURL "$BASEURL/admin/ci/variables" | jq -r '.[] ' > $EXPORTPATH/admin.variables.json
 
LAST_PROJ_ID=$( $CURL "$BASEURL/projects/" | jq -r '.[].id' | sort -n | tail -1 )
#echo $LAST_PROJ_ID
ID=1
until [ $ID -gt $LAST_PROJ_ID ]; do
 
# get the short name "path"
#NAME=$( $CURL "$BASEURL/projects/$PROJID/" | jq -r '.path' )
 
#echo ">>> $ID <<<"
LONGNAME=$( $CURL "$BASEURL/projects/$ID/" | jq -r '.path_with_namespace' | sed 's#/#__#g' )
 
#echo $LONGNAME
 
if [ "$LONGNAME" == "null" ]; then
    ((ID++))
    continue
fi
 
VARIABLES=$( $CURL "$BASEURL/projects/$ID/variables" | jq -r '.[]' )
 
if [[ ! -z "$VARIABLES" |]]; then
    printf "$VARIABLES" > $EXPORTPATH/project.variables.$ID.$LONGNAME.json
fi
 
((ID++))
 
done
 
# FINI
de/sysadmin/tools/gitlab-ci-variable-export.txt · Zuletzt geändert: 2023-09-12 14:59 von hella

Seiten-Werkzeuge

Mastodon Mastodon (old account)