Skip to content

Commit

Permalink
feat: add ignore_errors param
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleTryon committed Jul 19, 2023
1 parent 4bbdce0 commit e6f49ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/commands/notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ parameters:
description: "Enable additional logging if you are running into issues. A log will be generated at '/tmp/circleci_jira.log'."
type: boolean
default: false
ignore_errors:
description: "Ignore errors. Errors posting to Atlassian will not result in failed builds unless disabled."
type: boolean
default: true
steps:
- run:
when: on_fail
Expand Down Expand Up @@ -75,5 +79,6 @@ steps:
JSON_BUILD_PAYLOAD: <<include(scripts/build_payload.json)>>
JSON_DEPLOYMENT_PAYLOAD: <<include(scripts/deployment_payload.json)>>
JIRA_BOOL_DEBUG: <<parameters.debug>>
JIRA_BOOL_IGNORE_ERRORS: <<parameters.ignore_errors>>
name: Notify Jira
command: <<include(scripts/notify.sh)>>
27 changes: 18 additions & 9 deletions src/scripts/notify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ touch $JIRA_LOGFILE
# Ensure status file exists
if [ ! -f "/tmp/circleci_jira_status" ]; then
echo "Status file not found at /tmp/circleci_jira_status"
exit 1
exit 1 # Critical error, do not skip
fi

# Functions to create environment variables
Expand All @@ -17,9 +17,19 @@ getVCS() {
PROJECT_VCS="${BASH_REMATCH[1]}"
else
echo "Unable to determine VCS type"
exit 1 # Critical error, do not skip
fi
}

errorOut() {
echo "Exiting..."
STATUS=${1:-0}
if [[ "$JIRA_BOOL_IGNORE_ERRORS" == "1" ]]; then
STATUS=0
fi
exit "$STATUS"
}

# Get the slug given the build url
getSlug() {
if [[ "$PROJECT_VCS" == "circleci" ]]; then
Expand All @@ -35,7 +45,7 @@ getSlug() {
fi
if [[ ${#PROJECT_SLUG} -eq 0 ]]; then
echo "Unable to determine project slug"
exit 1
exit 1 # Critical error, do not skip
fi
}

Expand Down Expand Up @@ -67,7 +77,7 @@ getIssueKeys() {
echo "$message"
echo -e "$dbgmessage"
printf "\nSkipping Jira notification\n\n"
exit 0
errorOut 0
fi
# Set the JIRA_ISSUE_KEYS variable to JSON array
JIRA_ISSUE_KEYS=$(printf '%s\n' "${KEY_ARRAY[@]}" | jq -R . | jq -s .)
Expand Down Expand Up @@ -103,8 +113,7 @@ postForge() {
sleep 3
postForge "$FORGE_PAYLOAD" "$((COUNT + 1))"
elif [[ "$HTTP_STATUS" -gt 399 ]]; then
echo "Exiting..."
exit 1
errorOut 1
fi
}

Expand All @@ -115,19 +124,19 @@ verifyVars() {

if [[ -z "$JIRA_VAL_JIRA_OIDC_TOKEN" ]]; then
echo "'oidc_token' parameter is required"
exit 1
exit 1 # Critical error, do not skip
fi

if ! [[ "$JIRA_VAL_JIRA_WEBHOOK_URL" =~ ^https:\/\/([a-zA-Z0-9.-]+\.[A-Za-z]{2,6})(:[0-9]{1,5})?(\/.*)?$ ]]; then
echo "'webhook_url' must be a valid URL"
echo " Value: $JIRA_VAL_JIRA_WEBHOOK_URL"
exit 1
exit 1 # Critical error, do not skip
fi

if [[ -z "$JIRA_VAL_ENVIRONMENT" ]]; then
echo "'environment' parameter is required"
echo " Value: $JIRA_VAL_ENVIRONMENT"
exit 1
exit 1 # Critical error, do not skip
fi

}
Expand Down Expand Up @@ -230,7 +239,7 @@ main() {
postForge "$PAYLOAD"
else
echo "Unable to determine job type"
exit 1
exit 1 # Critical error, do not skip
fi
printf "\nJira notification sent!\n\n"
MSG=$(printf "sent=true")
Expand Down

0 comments on commit e6f49ff

Please sign in to comment.