gitlab pipeline run until pass looper.
This file contains 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