sharpliner / sharpliner

Use C# instead of YAML to define your Azure DevOps pipelines
https://www.nuget.org/packages/Sharpliner/
MIT License
285 stars 21 forks source link

Guard which variables are available in the template context #265

Open premun opened 1 year ago

premun commented 1 year ago

Context

There is a third column in this table that hints that not all variables are available when processing template parameters.

This table tells you whether you're allowed to pass that particular variable in the template compile-time expression. From the docs:

Within a template expression, you have access to the parameters context that contains the values of parameters passed in. Additionally, you have access to the variables context that contains all the variables specified in the YAML file plus many of the predefined variables (noted on each variable in that topic). Importantly, it doesn't have runtime variables such as those stored on the pipeline or given when you start a run. Template expansion happens very early in the run, so those variables aren't available.

from https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#context

Proposal

I don't have a clear idea of whether we could encode this information into the type system and prevent people using variables in the some places but logging this issue so it doesn't get forgotten.

premun commented 1 year ago

@thomhurst do you think this would bring some value?

thomhurst commented 1 year ago

It'd definitely be useful. It's similar to what I was trying to do before with the CompileTimeVariable and RuntimeVariable, but we found it just added complication.

If we could somehow do that while still keeping things simple, it's be great, but I'm not sure the best way to do that