Created
December 23, 2020 10:22
-
-
Save drugoi/b48b0c841797529a58a74754987c80d5 to your computer and use it in GitHub Desktop.
Script for Gitlab CI to post comment about build to JIRA
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 | |
# Find something like UKK-0000 in variables | |
# NOTE: Script will use only first match to post comment (head -1) | |
COMMIT_TICKET=$(echo $CI_COMMIT_MESSAGE | grep -e '[A-Z]\+-[0-9]\+' -o | head -1) | |
DESCRIPTION_TICKET=$(echo $CI_COMMIT_DESCRIPTION | grep -e '[A-Z]\+-[0-9]\+' -o | head -1) | |
BRANCH_TICKET=$(echo $CI_COMMIT_REF_NAME | grep -e '[A-Z]\+-[0-9]\+' -o | head -1) | |
# Check is variables not empty | |
if [[ -n "$COMMIT_TICKET" || -n "$BRANCH_TICKET" || -n "$DESCRIPTION_TICKET" ]]; then | |
JIRA_TICKET="" | |
# Priority: Ticket from commit message > Ticket from commit description > Ticket from branch name | |
if [ -n "$COMMIT_TICKET" ]; then | |
echo "COMMIT_TICKET used" | |
JIRA_TICKET=$COMMIT_TICKET | |
elif [ -n "$DESCRIPTION_TICKET" ]; then | |
echo "DESCRIPTION_TICKET used" | |
JIRA_TICKET=$DESCRIPTION_TICKET | |
else | |
echo "BRANCH_TICKET used" | |
JIRA_TICKET=$BRANCH_TICKET | |
fi | |
# Post comment to Jira | |
curl -s --location --request POST 'https://'$JIRA_SERVER'/rest/api/2/issue/'$JIRA_TICKET'/comment' \ | |
--insecure \ | |
--header 'Content-type: application/json' \ | |
--header 'Authorization: Basic '$JIRA_BASIC_AUTH'' \ | |
--data '{"body": "Стенд: *'$CI_COMMIT_REF_NAME'*\nВерсия: *'$BUILD_VERSION'*"}' >/dev/null | |
echo "Comment posted to ticket ${JIRA_TICKET}" | |
fi | |
# Commands for test | |
# sh ./internals/post-comment-jira.sh | |
# CI_COMMIT_MESSAGE="Yo Man [LOL-2917]" sh ./internals/post-comment-jira.sh | |
# CI_COMMIT_REF_NAME="feature-LOL-2020" sh ./internals/post-comment-jira.sh | |
# CI_COMMIT_MESSAGE="Yo Man [LOL-2917]" CI_COMMIT_REF_NAME=feature-LOL-2020 sh ./internals/post-comment-jira.sh | |
# CI_COMMIT_DESCRIPTION="LOL-2000, LOL-2020" CI_COMMIT_REF_NAME=feature-LOL-2020 sh ./internals/post-comment-jira.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment