Slack orb - reference a template from a seperate file

Im just trying to run circle ci with custom Slack notifications,

Like

version: '2.1'
orbs:
  slack: circleci/slack@4.1
jobs:
  notify:
    docker:
      - image: 'cimg/base:stable'
    steps:
      - slack/notify:
          custom: |
            {
              "blocks": [
                {
                  "type": "section",
                  "fields": [
                    {
                      "type": "plain_text",
                      "text": "*This is a text notification*",
                      "emoji": true
                    }
                  ]
                }
              ]
            }
          event: always
workflows:
  send-notification:
    jobs:
      - notify:
          context: slack-secrets

From offical docs example,

is there a way I can put a template in a seperate file and reference it?

is this forum that dead? just wonder

Hi @Star,

Thank you for posting your question on our forum!

It is possible to define your templates in a separate file, and then import them into your config.yml file.

One method to do this would be to store your templates in a .json file in your repository, and then use jq to parse out the template you want to use. I’ve created an example that you can reference in the following secret gist:

Pass in template from .json file for Slack Orb · GitHub

Please take a look, and let me know if this solution would work for your use-case.

1 Like