Azure Devops custom task task.json visible rule

Viewed 161

Hello I'm trying to set a visible rule for some of the inputs and I was wondering if we can use && and || together.

"visibleRule":"Resource = AAA && Command = Delete || Resource = BBB && Command = Delete"

"visibleRule":"(Resource = AAA && Command = Delete) || (Resource = BBB && Command = Delete")

can't quiet get this to work, I tried different combinations but no luck

1 Answers

I don't think you can nest query parts with ( and ). If I take a peek in the task samples built by MS for the pipelines, then variations are somewhat limited. Like:

"visibleRule": "appType != functionAppLinux && appType != \"\" && package NotEndsWith .war && Package NotEndsWith .jar"

"visibleRule": "command != logout && command != package && command != save"

"visibleRule": "command = install || command = ci || command = custom"

"visibleRule": "ConnectionType = AzureRM && WebAppKind != webAppLinux && WebAppKind != webAppContainer && WebAppkind != functionAppContainer && webAppKind != functionAppLinux && WebAppKind != \"\" && Package NotEndsWith .war && Package NotEndsWith .jar"

"visibleRule": "package EndsWith .war"

What I could suggest to try based on these samples (not tested myself):

"visibleRule": "Resource == AAA || Resource == BBB && Command == Delete"

Not sure if the sample only becomes visible for Resource AAA when the query part Command == Delete is true. In that case I expected your first sample should work as well.

Otherwise, if you can put a suffix to your "Resource" value, then you could use:

"visibleRule": "Resource EndsWith "_suffix" && Command == Delete

This sample should work as both rule parts will always evaluate.

Last check, is Command always visible? Or is it constrained by another visibleRule? I just found out some (virtually) sub input that was excluded while it's visibleRule-condition should evaluate as true and thus should be visible. But that was not the case. I left out the query part from the sub input where the parent input was hidden. Not a nice solution, but it works for me as it was always evaluated to true anyway.

P.S. Note that = is still allowed for usage to stay backward compatible. So it's funny to see that if you know that officially == can be used since quite a long time.

Related