sharpliner / sharpliner

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

The "PublishDefinitions" task failed unexpectedly in 1.5.0 #269

Closed mathiasi closed 1 year ago

mathiasi commented 1 year ago

I have a project that was using 1.4.12 however when I update to the latest 1.5.0 and build the exact the project I get the following error:

MSBuild version 17.4.1+fedecea9d for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  PipelineProject -> C:\src\foo\bar\PipelineProject\PipelineProject\bin\Debug\net7.0\PipelineProject.dll
  Publishing all definitions inside bin\Debug\net7.0\PipelineProject.dll
  Using DefaultSharplinerConfiguration for configuration
  CiCdPipeline / pr.yml:
    Validating definition..
C:\Users\mathiasi\.nuget\packages\sharpliner\1.5.0\build\Sharpliner.targets(20,5): error MSB4018: The "PublishDefinitions" task failed unexpectedly. [C:\src\foo\bar\PipelineProject\PipelineProject\PipelineProject.csproj]
C:\Users\mathiasi\.nuget\packages\sharpliner\1.5.0\build\Sharpliner.targets(20,5): error MSB4018: (Line: 1, Col: 1, Idx: 0) - (Line: 1, Col: 1, Idx: 0): Expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS, got MappingEnd [C:\src\foo\bar\PipelineProject\PipelineProject\PipelineProject.csproj]

Build FAILED.

C:\Users\mathiasi\.nuget\packages\sharpliner\1.5.0\build\Sharpliner.targets(20,5): error MSB4018: The "PublishDefinitions" task failed unexpectedly. [C:\src\foo\bar\PipelineProject\PipelineProject\PipelineProject.csproj]
C:\Users\mathiasi\.nuget\packages\sharpliner\1.5.0\build\Sharpliner.targets(20,5): error MSB4018: (Line: 1, Col: 1, Idx: 0) - (Line: 1, Col: 1, Idx: 0): Expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS, got MappingEnd [C:\src\foo\bar\PipelineProject\PipelineProject\PipelineProject.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.80
premun commented 1 year ago

Hi, thanks for the report. Could you share the definition? At least some parts of it?

mathiasi commented 1 year ago

I managed to narrow it down and I think it is related to the Publish-task (not sure if that is the only one though). This definition fails for me:

public class TestPipeline : SingleStagePipelineDefinition
{
    public override string TargetFile => "eng/pr.yml";
    public override TargetPathType TargetPathType => TargetPathType.RelativeToGitRoot;

    public override SingleStagePipeline Pipeline => new()
    {
        Jobs = new()
        {
            Job("foo") with
            {
                Steps = new()
                {
                    Publish("artifactName", "some/file/path.txt")
                }
            }
        }
    };
}
premun commented 1 year ago

Thanks for spending time on this, I will have a look tomorrow. There were quite a lot of changes so it's possible there's a regression.

premun commented 1 year ago

@mathiasi I found the issue to be here: https://github.com/sharpliner/sharpliner/blob/c0bf72f5b9083fecf068c19aaf13f7df6ad6e277/src/Sharpliner/AzureDevOps/AzureDevOpsDefinition.cs#L281

I will push a new fixed version of the library but there is also a workaround possible if you provide display name to the Publish task.

mathiasi commented 1 year ago

I can confirm that it worked for the case of the PublishTask however I came across another case:

Task("CopyFiles@2") with
{
    Inputs = new()
    {
        { "contents",  "path/to/content"},
        { "targetFolder", "path/to/target" }
    }
};

which used to be valid since the displayName parameter of Task is optional. However it seems to suffer from the same as the PublishTask.

premun commented 1 year ago

Oh yeah, another NRE.. Thanks! I should have looked for all places like that.

Fix will be in 1.5.2 shortly.