Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the extensibility attribute to allow specify custom steps #1406

Open
MikDal002 opened this issue Aug 4, 2024 · 0 comments
Open

Add the extensibility attribute to allow specify custom steps #1406

MikDal002 opened this issue Aug 4, 2024 · 0 comments

Comments

@MikDal002
Copy link

MikDal002 commented Aug 4, 2024

Description

Hello :)
During my work with Nuke, I've come across some places where increased extensibility would be a benefit. That's why I've developed an approach with custom steps. I would like to share with you my implementation.
As in shown in Usage Example, I think it is a good idea to add possibility to write own custom steps and address them by attributes. Considering the current architecture of Nuke, it gives a great extensibility without big amount of changes.

I've written the usage example from the top of my head because at this moment I do not have access to my code.

Usage Example

public class TestBuild : NukeBuild
{
    [AzureDevOpsDownloadSecureFileStep("securefile.zip")]
    public Target Test => _ => _
        .DependsOn(Compile)
        .Produces(TestResultDirectory / "*.trx")
        .Produces(TestResultDirectory / "*.xml")
        .Partition(2);
}
// User provided implementations
class AzureDevOpsDownloadSecureFileStepAttribute : AzurePipelineStepAttribute
{
    public AzureDevOpsDownloadSecureFileStepAttribute(string fileName)
    {
        FileName = fileName;
    }

    public string FileName { get; }

    public override AzurePipelinesStep Get()
    {
        return new AzureDevOpsDownloadSecureFileStep(FileName);
    }
}

class AzureDevOpsDownloadSecureFileStep : AzurePipelinesStep
{
    public AzureDevOpsDownloadSecureFileStep(string fileName)
    {
        FileName = fileName;
    }

    public string FileName { get; }
    public override void Write(CustomFileWriter writer)
    {
        writer.WriteLine("- task: DownloadSecureFile@1");
        using (writer.Indent())
        {
            writer.WriteLine("inputs:");
            using (writer.Indent())
            {
                writer.WriteLine($"secureFile: '{FileName}'");
            }
        }
    }
}

Alternative

Alternative is to write all YAML pipelines by hand, but I do not want that as in a team not everybody must be fluent with .yml files. That's why I like the idea to generate as much pipeline code as possible by Nuke.

Could you help with a pull-request?

Yes [#1407]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant