-
Notifications
You must be signed in to change notification settings - Fork 0
Reuse Custom Templates
While you can provide a custom template via the custom
parameter, these custom templates are not reusable and add many lines to your config.
If you have created a custom template that you wish to use in multiple projects, it is possible to share the template and reduce the amount of lines added to your config using Contexts.
A Context on CircleCI is a "bucket" of environment variables that can be injected in your jobs across multiple projects.
Begin by designing your desired template.
You can use Markdown to structure the message for Glue. When complete, copy the markdown template to your clipboard.
Note: You can reference environment variables (example: ${CIRCLE_JOB}
) in the template directly, and they will be populated at run-time.
Follow the CircleCI docs to create a Context, and give your Context a name such as glue-templates
.
Now you can create environment variables containing your Glue template (in Markdown) that was copied earlier. The name you give the environment variable will be the name of the template.
Contexts are added to jobs via your workflow, and you can add as many as you need. Any job with the context we have created here will be able to access these templates via the template
parameter using the name of the environment variable for that template.
Here is a full example:
version: '2.1'
orbs:
glue: gluegroups/[email protected]
jobs:
my-job:
docker:
- image: 'cimg/base:stable'
steps:
- glue/notify:
event: always
template: MY_GLUE_TEMPLATE
target: thr_ABC123
workflows:
my-workflow:
jobs:
- my-job:
context: glue-templates
The templates within glue-templates can now be imported this way in all projects within the organization.