From 793877e39aa8eaec84e29596ad68f20da5c0dae1 Mon Sep 17 00:00:00 2001 From: Jessica Wagantall Date: Tue, 11 Jul 2017 13:40:36 -0700 Subject: [PATCH] Check for JIRA URLs on JIRA based projects Check if the project has a JIRA_URL defined in Jenkins and, if so, check if there are JIRA URLS in the commit text. Ignore checks for projects that don't use JIRA Change-Id: I2267aa98e1b6a9c727fb9a54426aef5c5a7131e6 Signed-off-by: Jessica Wagantall --- shell/git-validate-jira-urls.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/shell/git-validate-jira-urls.sh b/shell/git-validate-jira-urls.sh index 51d5132a..e542c450 100644 --- a/shell/git-validate-jira-urls.sh +++ b/shell/git-validate-jira-urls.sh @@ -12,13 +12,19 @@ # This script will make sure that there are no JIRA URLs in the commit # message. JIRA URLs will break the its-jira plugin +# Ensure we fail the job if any steps fail. +# Do not treat undefined variables as errors as in this case we are allowed +# to have JIRA_URL undefined set -e -o pipefail set +u -JIRA_LINK=$(git rev-list --format=%B --max-count=1 HEAD | grep -io 'http[s]*://jira\..*' || true) -if [[ ! -z "$JIRA_LINK" ]] +if [ -n "${JIRA_URL}" ]; then - echo 'Remove JIRA URLs from commit message' - echo 'Add jira references as: Issue: -, instead of URLs' - exit 1 + JIRA_LINK=$(git rev-list --format=%B --max-count=1 HEAD | grep -io 'http[s]*://jira\..*' || true) + if [[ ! -z "$JIRA_LINK" ]] + then + echo 'Remove JIRA URLs from commit message' + echo 'Add jira references as: Issue: -, instead of URLs' + exit 1 + fi fi -- 2.16.6