diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 920f7f97..7d687b69 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -160,6 +160,42 @@ jobs: } ] } + - run: + name: Export value to file + command: | + printf '%s\n' "Hello There!" > /tmp/msg + - slack/notify: + debug: true + step_name: "Notify with custom message coming from sub-shell and template variable" + event: always + custom: | + { + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "Current Job: $CIRCLE_JOB" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "$(cat /tmp/msg)" + } + } + ] + } + - slack/notify: + debug: true + step_name: "Notify with only custom message coming from sub-shell" + event: always + custom: | + { + "type": "mrkdwn", + "text": "$(cat /tmp/msg)" + } workflows: test-deploy: diff --git a/src/scripts/notify.sh b/src/scripts/notify.sh index f489c2b2..93b8fa8a 100644 --- a/src/scripts/notify.sh +++ b/src/scripts/notify.sh @@ -196,7 +196,8 @@ SanitizeVars() { # Extract the variable names from the matches. local variable_names - variable_names="$(printf '%s\n' "$variables" | grep -o -E '[a-zA-Z0-9_]+')" + variable_names="$(printf '%s\n' "$variables" | grep -o -E '[a-zA-Z0-9_]+' || true)" + [ -z "$variable_names" ] && { printf '%s\n' "Nothing to sanitize."; return 0; } # Find out what OS we're running on. detect_os