Created
February 14, 2020 05:36
-
-
Save devzer01/98db6f8bc45eb0818695aac5f831cc39 to your computer and use it in GitHub Desktop.
gitlab pipeline run until pass looper.
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 | |
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