Skip to content
Svyatoslav Reyentenko edited this page Aug 23, 2013 · 5 revisions

To reuse a parts of DSL you can declare and use simple macros in the body of template. This is experimental feature.

Macro declaration

Macros are declared with a word defmacro following by quoted macro name, colon and macro body. Macro body is a Groovy closure. Macro arguments are passed as usual closure arguments, but they are prepended with a $ symbol. You should not use reserved variables ($project, $context, $env, $databags and so on) as macros arguments, though you're free to use them in macro body. Variables can have default values.

defmacro "my_macro" : { $message, $value = "my_value" ->
   my_step {
      value = $value
      message = $message 
   }
}

Macro usage

When you need to use macro in template body, you should call it as a method prepended by a label 'macro'. Arguments may be positional or prepended with name labels, but you cannot mix these styles. For example, this call is valid:

steps {
   macro:my_macro("Message", "value")
}

This call is valid too:

steps {
   macro:my_macro($message: "Message")
}

But this is not:

steps {
   macro:my_macro($message: "Message", "Value")
}

You can use any valid Groovy values as arument values.

Clone this wiki locally