Skip to content

Instantly share code, notes, and snippets.

@valentin-harrang
Last active September 17, 2024 14:00
Show Gist options
  • Save valentin-harrang/e8b40a9436ebd27f039479a637985d7d to your computer and use it in GitHub Desktop.
Save valentin-harrang/e8b40a9436ebd27f039479a637985d7d to your computer and use it in GitHub Desktop.
Detecting JIRA Ticket in Merge Request Title and Executing Transition to ID 3
#!/bin/bash
echo "Verifying 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 was found in the Merge Request title."
exit 0 # Do nothing if no ticket is found
fi
echo "Updating JIRA ticket ${JIRA_ISSUE} to move it to transition ID 3..."
curl -u "$JIRA_EMAIL:$JIRA_API_TOKEN" \
-X POST \
-H "Content-Type: application/json" \
--data '{
"transition": {"id": "3"}
}' \
"$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