Core Substitution Context
Template Branch
Variable substitution for the branch of a template.
A template branch in Stubber refers to a version of your template—specifically, either the draft or live branch. There are situations where it's important to reference the branch of a stub, particularly when you want to execute different actions based on the environment. For example, you might send a notification to one number or email when a stub is running in the live environment, and a different one when it's in the draft environment. Similarly, you may want to run certain tasks differently—or not at all—depending on the template branch.
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.