Skip to content

Instantly share code, notes, and snippets.

@devzer01
Created February 14, 2020 05:36
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 devzer01/98db6f8bc45eb0818695aac5f831cc39 to your computer and use it in GitHub Desktop.
Save devzer01/98db6f8bc45eb0818695aac5f831cc39 to your computer and use it in GitHub Desktop.
gitlab pipeline run until pass looper.
#!/bin/bash
PRIVATE_TOKEN="create from your gitlab profile"
TRIGGER_TOKEN="get from the project ci/cd triggers"
GITLAB_URL="https://gitlab.com"
PROJECT_ID="you can find this using gitlab api or under the gitlab project settings"
REF="master" #this can also be a branch name or a commit hash
SLEEP_SECONDS=1
while true
do
status=$(curl --silent --request GET --header "PRIVATE-TOKEN: ${PRIVATE_TOKEN}" \
"${GITLAB_URL}/api/v4/projects/${PROJECT_ID}/pipelines?ref={$REF}" | jq -r '.[0].status')
echo $status
if [ $status == "failed" ];then
curl -X POST \
-F token=${TRIGGER_TOKEN} \
-F ref=${REF} \
${GITLAB_URL}/api/v4/projects/${PROJECT_ID}/trigger/pipeline
sleep 5 # we wait here for 5 seconds for the pipeline to start to prevent duplicate triggering
elif [ $status == "running" ];then
echo "pipeline running"
fi
sleep ${SLEEP_SECONDS}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment