Hi all,
I have an issue with CircleCi config.yaml version 2.1 and passing/evaluating variables. I have a script that creates a summary of a file and stores it as variable in $BASH_ENV. This variable needs to be evaluated/echoed in CircleCi’s slack orb as json custom message but unfortunately this throws a parsing error. I tried with setting a simple “hello” message but jq still cannot parse it. If I echo the variable in a different step it shows the contents of this variable correctly.
In my main job I am using a custom private image that the commands runs in, without affecting $BASH_ENV or any environment variables.
Let me know if someone can help or if I am doing something wrong on that matter.
Best Regards and thank you
config.yml
version: 2.1
orbs:
slack: circleci/slack@4.3.0
commands:
custom_slack_message:
steps:
- run:
command: |
./scripts/store_variable.sh
- slack/notify:
custom: |
{"blocks": [{"type": "section", "text": {"type": "mrkdwn", "text": $MESSAGE }}]}
event: always
channel: "a-channel"
scripts/store_variable.sh
#!/bin/bash
# GET THE PLAN FILE
FILE="./.terraform/plan/tfplan"
# GET THE DIFF
plan_diff=$(terraform show $FILE | grep -E "^\s*[#~+-]")
echo "export MESSAGE=\"Changes to be applied from terraform: \`\`\`$plan_diff\`\`\`\"" >> $BASH_ENV; source $BASH_ENV;