Scripting syntax for boolean parameters

I am currently trying to append a directory name to a command based on a boolean parameter value

e.g
parameter is defined as:

name: shared
type: boolean

this should then be added to my command execution via the text template syntax… but i cannot find any documentation on this … the samples only show the “if” case not the else case … let me show what i want:

cmake xxx -o targetpath/somepath/<<# parameters.shared >>shared</parameters.shared>><>static

so the result would be
cmake xxx -o targetpath/somepath/shared if the parameter shared is true, and
cmake xxx -o targetpath/somepath/static if the parameter shared is false…

What would be the correct syntax for this ?

I’m not too familiar with conditionals in CircleCI syntax, but I guess you could do this with Bash conditionals?

Yes but that would be troublesome for other platforms as bash is not available to me on all executors.

Ah, I see. Mac and Linux will support shell conditionals, so I take it you want to run the Windows executor as well?

exactly, i mean i can use bash there, but bash on windows has problems with cmake parameter parsing ( i have to call that via cmd.exe to make it work )

The docs have an exact example for the if case only, i can’t imagine someone implementing if without thinking about the else case as well:

<<# parameters.all >> -a <</ parameters.all >>

Is given in the article about parameters

Gotcha. Well, in the interests of getting it working immediately, you could use a scripting language that works identically on all platforms, such as PHP or Python (assuming the parameter can be passed from the step to the script).

From there, you can always refactor if and when it becomes clearer how to do this in a more native way. (This approach serves me well generally - rather than spend hours/days on working out how to do something the correct way, I make a reasonably clean hack and then create a ticket to clean it up. Sometimes I am reasonably satisfied with the hack and decide to leave it be anyway).

Actually that’s a pretty good idea. I will go the python route i think

1 Like

Just FYI, it looks like it’s been updated in documentation: Reusable Config Reference Guide - CircleCI

While the “if”/“truthy” check is:
<<# parameters.all >> -a <</ parameters.all >>
the “if not”/“falsey” check is:
<<^ parameters.short >> -l <</ parameters.short >>

There is a support document for the syntax. I can not post links, but go to support dot circleci dot com, and then search for “Using Mustache Conditionals in Config File”. You should see article ID 4417604103835 by Aaron, September 2022.

I think it is misleading to call these “Mustache Conditionals”. Since mustache uses curly braces, a section would look like:

{{# parameters.all }} -a {{/ parameters.all }}

and an inverted section like:

{{^ parameters.short }} -l {{/ parameters.short }}

In CircleCI, these are angle brackets:

<<# parameters.all >> -a <</ parameters.all >>

and an inverted section like:

<<^ parameters.short >> -l <</ parameters.short >>