Macro Blocks
Consider using module instead of macros.
Macros are reusable stages. If you would like to reuse the same stage multiple times
in the same pipeline, with optionally different parameters, macros are the right
thing for you.
You may use macro in three ways:
- Inline stages (
stageblock): The stage is defined in the macro block, and re-used multiple times - External files (
sourceargument): Path to an external single pipeline located on the filesystem, which will be passed to an internal togomak child process, which will independently run the single file as a separate stage. - Pipeline content (
filesargument): A map containing files inline, which will be used by togomak, to create another child process which will run the contents of the file, as an independant stage.
Before you decide to use macro, you might be interested in seeeing
import block. See also What's the difference between macro and import?
Example usage (Inline stages)
togomak {
version = 2
}
macro "explode" {
stage "explode" {
script = <<-EOT
for i in $(seq 1 10); do
sleep 0.1
echo "${param.eva}: Loading $i..."
done
echo "${param.eva}: entry plug connected! pilot ${param.pilot} synchronized! 🤖"
EOT
}
}
stage "entry_plug_eva01" {
use {
macro = macro.explode
parameters = {
pilot = "Shinji Ikari 🙅♂️"
eva = "01"
}
}
}
stage "entry_plug_eva02" {
use {
macro = macro.explode
parameters = {
pilot = "Asuka Langley Soryu 🙅♀️"
eva = "02"
}
}
}Argument reference
stage- The stage that will be reused, optional. Structure documented belowsource- Path to a different togomak file, which will be recursively invoked.files- a map containing key value pairs of file paths to file content. Map documented below
The stage block supports:
- All features under the
stage, exceptid,name,description
The files is a map, which accepts data in the format of key-value pairs, where the "key" is the path to the file
and the "value" is the content of the file.
For example,
files = {
"togomak.hcl" = <<-EOT
togomak {
version = 2
}
stage "hello" {
script = "echo hello world"
}
EOT,
...
}As a general note, macro blocks and module blocks are very similar in how they work. macro uses a child subprocess,
while module uses a goroutine. module blocks offer a better path resolution by correctly resolving
path.module, path.cwd and path.owd if you are looking to resolve relative paths (relative to the module, or relative to current working directory, etc.).
macro blocks, on the other hand, do not correctly resolve path.module.