-
Notifications
You must be signed in to change notification settings - Fork 204
Dynamic Templates
It is possible to dynamically write or create a Slack Orb template as a part of the job the orb is running in, and then have the orb pick up that template at the time of sending the notification.
This means, it is possible to write orbs, which can be used with the Slack orb to send special notifications.
Either within your config, or as a part of your orb's command, write to a file your orb template.
You can get the basic structure of your template from the Block Kit Builder and customize the code with utilities such as JQ.
- Generate orb template
- Write to /tmp/MyOrbName/SlackTemplate.json
With your template file in the system, we can now export the template as an environment variable. On CircleCI we need to make use of the $BASH_ENV
environment variable, to persist our environment across steps.
echo 'export MY_ORB_TEMPLATE=$(cat /tmp/MyOrbName/SlackTemplate.json)' >> $BASH_ENV
You may now use the template within the Slack orb later in the job as if it were any of the included default templates.
- slack/notify:
event: fail
template: MY_ORB_TEMPLATE
channel: ABCXYZ