Suppressing entire blocks with mustache templating

I got some help earlier about using mustache templating to suppress a value

But supposed instead of setting an env var to null (for example), is there a way to suppress an entire block of code? So given, e.g.,

  environment:
     FOO: << parameters.foo >>
     BAR: << parameters.foo >>

is there a way to entirely suppress the environment block and / or the parameters themselves? Or is setting a null value for the value of the parameter the best I can do? Is there a way to suppress / add newlines like you could in other templating languages to skip entire sections?

I tried something like this, but then YAML validation fails.

<<#parameters.foo>>
environment:
  FOO: << parameters.foo >>
  BAR: << parameters.foo >>
<</parameters.foo>>

If I separately put <<#parameters.foo>> and <<^parameters.gcloud-project>> around each side of the elements in the block, it gets somewhat close to what I’m trying to do, but is almost unreadable.

I can find the docs about mustache itself, but not very much about Circle’s use of it, are there any public docs, or is this mostly intended as something for internal use?

In this example, the goal is to have the env vars not set at all when the parameter isn’t defined, vs. setting it but to an empty value.

2 Likes

Can CircleCI document this mustache thing somewhere? It seems like something many people would find useful. Does it only apply to circleci configs or just orbs?

FWIW, not sure if this is what you’re asking, but in a general sense, Mustache is a JS templating framework (https://github.com/janl/mustache.js/)