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

[Question] How to Reference Job Library? #189

Closed jeffward01 closed 2 years ago

jeffward01 commented 2 years ago

THANK YOU FOR THIS LIBRARY!!

I very much dislike .yml templates and feel at home in C# code. I am loving this library and plan to contribute a NugetInstallerBuilder once I finish these Pipeline tasks.

I have a question about how to reference a Job Library.

I am able to reference Step Libraries without any issue, however, when I try and do the same with a JobLibrary<> I receive errors.

image

From the documentation, you can reference a StepLibrary like this (This works fine for me):

 new Job("Build")
    {
        Steps =
        {
            Script.Inline("echo 'Hello World'"),

            // I can run this example with no issues
            StepLibrary<ProjectBuildSteps>(),

            Script.Inline("echo 'Goodbye World'"),
        }
    }

My Error

However, when I run the example above when attempting to reference a JobLibrary<> I receive an error:

_jobLIbrary_Error

My class which implements JobLibrary is defined below:


internal class JobBuildDeployPackNugetPackage : JobLibrary
{
    public override List<Conditioned<Job>> Jobs =>
        new()
        {
            new Job("RestoreBuildPackDeployPackage")
            {
                Pool = new HostedPool("$(DefaultBuildAgentWin)"),

                Steps =
                {
                    StepLibrary<StepInstallNet6Sdk>(),

                    StepLibrary<StepNugetToolInstallerV6>(),

                    StepLibrary<StepNugetRestoreSolution>(),

                    Script.Inline("echo 'Hello World'"),

                    Script.Inline("echo 'Goodbye World'")
                }
            }
        };
}

Question

Am I doing something wrong? Can you please provide a simple example referencing a job library?


Thanks so much again! This is a great library!!! I am surprised that Microsoft has not done this yet. I can see Microsoft adopting this library once it matures!

Thanks so much!

premun commented 2 years ago

Hi,

Thanks for the feedback and for the bug report! I am very glad Sharpliner makes someone's life easier!

You are not doing anything wrong, there's a bug in Sharpliner. This is a regression from when I was adding DeploymentJob and adding a common ancestor for Job and DeploymentJob which is called JobBase. The problem is that the JobLibrary should be defined as JobBase and not Job.

The fix is super easy, I will have a new version for you in second, please bare with me!

premun commented 2 years ago

The fix has been published in version 1.3.1 which should appear listed on nuget.org shortly.

Thanks for the extensive report again, it was super easy to determine the cause thanks to this!