Created
September 17, 2024 13:58
-
-
Save valentin-harrang/d3886e593665ad80116819405f72a3de to your computer and use it in GitHub Desktop.
Checking for JIRA Ticket in Merge Request Title and updating transition in CI Pipeline
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 | |
echo "Check if the Merge Request is Draft..." | |
if [[ "$CI_MERGE_REQUEST_TITLE" =~ "Draft" ]]; then | |
echo "The Merge Request is in draft. No JIRA action will be taken." | |
exit 0 | |
fi | |
echo "Check if the Merge Request title contains a JIRA ticket number..." | |
if [[ "$CI_MERGE_REQUEST_TITLE" =~ \[(TT-[0-9]+)\] ]]; then | |
JIRA_ISSUE="${BASH_REMATCH[1]}" | |
echo "JIRA ticket number found: ${JIRA_ISSUE}" | |
else | |
echo "No JIRA ticket number found in the Merge Request title." | |
exit 0 # We do nothing if no ticket is found | |
fi | |
echo "Update JIRA ticket ${JIRA_ISSUE} in JIRA..." | |
curl -u "$JIRA_EMAIL:$JIRA_API_TOKEN" \ | |
-X POST \ | |
-H "Content-Type: application/json" \ | |
--data '{ | |
"transition": {"id": "7"} | |
}' \ | |
"$JIRA_API_URL/rest/api/3/issue/${JIRA_ISSUE}/transitions" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment