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

It should be possible to inject a parameter reference to any type of pipeline #255

Closed premun closed 1 year ago

premun commented 1 year ago

Problem

It is currently not possible to create following YAML template:

parameters:
  agentOs: ''
  steps: []

steps:
- ${{ if eq(parameters.agentOs, 'Windows_NT') }}:
  - ${{ parameters.steps }}

There is no mechanism to inject parameter reference instead of an arbitrary piece of the definition.

The C# for this would look something like this:

public class RunOnWindowsTemplate : StepTemplateDefinition
{
    public override string TargetFile => "run-on-windows.yml";

    public override List<Parameter> Parameters => new()
    {
        StringParameter("agentOs"),
        StepListParameter("steps"),
    };

    public override ConditionedList<Step> Definition => new()
    {
        If.Equal(parameters["agentOs"], "Windows_NT")
            .Step(/* New stuff goes here */)
    };
}