Created
April 30, 2020 15:15
-
-
Save adamrushuk/60791979cfd734e81be0d65e45b6a080 to your computer and use it in GitHub Desktop.
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 | |
# Set GitLab pipeline status | |
# vars | |
GITLAB_URL="https://gitlab.domain.com" | |
GITLAB_TOKEN="<your_access_token>" | |
# status can be one of: running, pending, success, failed, canceled, skipped, created, manual | |
STATUS="success" | |
# get required info | |
GIT_COMMIT_HASH="$(git log -n 1 --pretty=format:'%H')" | |
PROJECT_ADDRESS=$(git config --get remote.origin.url | cut -c36- | rev | cut -c5- | rev | sed -e 's/\//%2f/g') | |
PROJECT_ID=$(curl --silent --request GET --header "PRIVATE-TOKEN: $GITLAB_TOKEN" $GITLAB_URL/api/v4/projects/$PROJECT_ADDRESS | jq '.id') | |
# set latest commit pipeline status | |
echo "Setting Project ID: [$PROJECT_ID] pipeline status to [$STATUS] for commit: [$GIT_COMMIT_HASH]" | |
curl --silent --request POST --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "$GITLAB_URL/api/v4/projects/$PROJECT_ID/statuses/$GIT_COMMIT_HASH?state=$STATUS" | jq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment