Skip to content

Dynamic Templates

Kyle T edited this page Nov 20, 2020 · 2 revisions

Dynamic Slack Orb 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.


1. Generate the template.

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

2. Export Template To Environment Variable

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

3. Use The Template

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