Skip to content

Instantly share code, notes, and snippets.

@ticapix
Created June 15, 2021 07:33
Show Gist options
  • Save ticapix/5ebd8c1de32257cf1f20d05adde8fcff to your computer and use it in GitHub Desktop.
Save ticapix/5ebd8c1de32257cf1f20d05adde8fcff to your computer and use it in GitHub Desktop.
Small Gitlab runner from local .gitlab-ci.yml file
#!/bin/bash
set -e
which yq > /dev/null || (echo 'yq is missing, please install it. pip install yq'; exit 1)
cifile=".gitlab-ci.yml"
echo "Using file ${cifile}"
if [ $# -eq 0 ]; then
cat "${cifile}" | yq -r '. | to_entries[] | select(.value|objects) | select(.value.stage != null) | .key' | cat -n
echo "which one ?"
read idx
else
idx=$1
fi
target=$(cat "${cifile}" | yq -r '[. | to_entries[] | select(.value|objects) | select(.value.stage != null) | .key]'"[$idx-1]")
echo "running $target"
set -x
job() {
target=$1
# SOURCE VAR from GITLAB
source <(cat "${cifile}" | yq -r '.variables | to_entries[] | "export " + .key + "=" + (.value | tostring)')
source <(cat "${cifile}" | yq -r '.["'"$target"'"].variables | to_entries[] | "export " + .key + "=" + (.value | tostring)')
# CUSTOM
# export NEO4J_VERSION=4.1.3-1
# unset DOCKER_HOST
export CI_COMMIT_SHORT_SHA=local
# EXEC SCRIPT
source <(cat "${cifile}" | yq -r '.["'"$target"'"].script[]')
}
job $target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment