Macro
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 (
stage
block): The stage is defined in the macro block, and re-used multiple times - External files (
source
argument): 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. See Reusable Stages section for more information. - Pipeline content (
files
argument): 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
- 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,
...
}