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

Add a warning when variables defined in matrix are used in compile time expressions #258

Open premun opened 1 year ago

premun commented 1 year ago

Context

When you define a matrix in YAML, e.g.

strategy:
  matrix:
    Release:
      _BuildConfig: Release
    Debug:
      _BuildConfig: Debug

you cannot use _BuildConfig in compile time expressions such as these:

${{ if eq(variables['_BuildConfig'], 'true') }}
   ...

You can only reference them from the condition property that is evaluated on runtime.

Goal

Add a new pipeline validation that checks for variables defined in a matrix (we can get all matrix objects from the whole definition) and compare it to the list of variables used in ${{ if }} blocks. If there's a match, output a warning for the user to know about this when they compile the pipeline.