sharpliner / sharpliner

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

Make it possible to add 1-line inline scripts easier #127

Open premun opened 3 years ago

premun commented 3 years ago

Motivation

Many times you want to include a very long shell call as a script that should fit into 1 line, e.g.:

dotnet tool install Microsoft.DotNet.XHarness.CLI                                                   \
    --global                                                                                        \
    --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json \
    --version "1.0.0-prerelease*"

However, you need to escape the EOLs or you need to concatenate it as a long C# string which then makes it harder to read in the YAML.

Goal

Make some API that would tell YAML to use the notation where it concatenates lines of an array it receives via the > sign and allow user to supply an array of strings.

Or some other pleasant way of dealing with this use case.

Meir017 commented 1 week ago

I think generating something like this would work:

steps:
  - powershell: |
      dotnet tool install `
      Microsoft.DotNet.XHarness.CLI `
      --global `
      --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json `
      --version "1.0.0-prerelease*" `

I think this approach is powershell specific, but doing something similar for bash can work as well found this https://yaml-multiline.info/ which is really helpful for me to understand this,

we could introduce a new type that will implement IYamlConvertible and force the scalar value to be a multiline string (using the enum values ScalarStyle.Literal and ScalarStyle.Folded)