Skip to content

Instantly share code, notes, and snippets.

@adamrushuk
Created April 30, 2020 15:15
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 adamrushuk/60791979cfd734e81be0d65e45b6a080 to your computer and use it in GitHub Desktop.
Save adamrushuk/60791979cfd734e81be0d65e45b6a080 to your computer and use it in GitHub Desktop.
#!/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