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

Automatically wrap string expressions in condition in apostrophes #227

Closed thomhurst closed 1 year ago

thomhurst commented 1 year ago

Take this variable condition:

        Variables =
        {
            StartsWith("refs/head/feature/", variables.Build.SourceBranch).Variable("myvariable", "pr-variable")
                .Else.Variable("myvariable", "other-variable"),
        },

The yaml being produced is:

variables:
- ${{ if startsWith($(Build.SourceBranch), refs/head/feature/) }}:
  - name: myvariable
    value: pr-variable
- ${{ else }}:
  - name: myvariable
    value: other-variable

I get this exception: image

I think both of these values in the Contains/StartsWith/EndsWith conditions need to be made into strings. i.e. adding quotes around them

thomhurst commented 1 year ago

I've proposed this solution. Let me know if you think it's bad.

229

premun commented 1 year ago

Thanks again for the contribution, @thomhurst! You can find the new updates in the 1.4.0 package.

Actually, with the if does not start with ' it's probably not even a breaking change but I have already tagged it like 1.4.0 so we have that now.