Core Substitution Context
Template Branch
Variable substitution for the branch of a template.
There are situations where it's important to know whether a stub is running on the live or draft branch. This is especially useful when you want to execute different actions based on the environment. For instance, you might want to send a notification to a specific channel when a stub is running in the live environment.
Usage
You can use the substitution stub.program.branch
or template.branch
to dynamically insert the branch of the current template into your action definitions. This is particularly helpful when executing tasks like sending notifications, logging actions, or performing environment-specific logic.
Example 1: Storing a Branch-Specific Message
Action definition:
Substituted definition:
Assuming the template is running on the live branch:
In this example, the stub.program.branch
substitution is replaced with the actual branch of the template (live
). This ensures that the correct branch is inserted into the message without needing to manually update the value.
Example 2: Conditional API Call Based on Branch
In this example, the condition stub.program.branch === 'live'
checks if the template is running on the live branch. If the condition is met, the API call is executed. This allows you to automate actions specific to the environment, such as running tests in a draft branch while performing production tasks in the live branch.