nuke icon indicating copy to clipboard operation
nuke copied to clipboard

Easier configuration of CI file output directory and name

Open jussimattila opened this issue 6 years ago • 2 comments

Description

Files generated by CI attributes (e.g. AzurePipelinesAttribute) are written into project root. Since the properties controlling output file folder and name are private, they cannot be modified by a deriving class:

private string ConfigurationFileName => _suffix != null ? $"azure-pipelines.{_suffix}.yml" : "azure-pipelines.yml";
private string ConfigurationFile => NukeBuild.RootDirectory / ConfigurationFileName;

It is possible to change the output file folder and name by deriving the attribute class and overriding its GeneratedFiles property and CreateWriter() method. This makes the derived class a bit more verbose than should be needed (see example below). My proposal is to make the private fields virtual protected so that subclasses can more easily configure where the file is written.

Here's an example what I did to write into build folder with additional .nuke. suffix:

public class CustomAzurePipelinesAttribute : AzurePipelinesAttribute
{
    public const string AzurePipelineYamlFolder = "build";
    readonly string suffix;

    public CustomAzurePipelinesAttribute([CanBeNull] string suffix, AzurePipelinesImage image, params AzurePipelinesImage[] images) : base(suffix, image, images)
    {
        this.suffix = suffix;
    }

    private string ConfigurationFileName => suffix != null ? $"azure-pipelines.{suffix}.nuke.yml" : "azure-pipelines.nuke.yml";
    private string ConfigurationFile => NukeBuild.RootDirectory / AzurePipelineYamlFolder / ConfigurationFileName;

    public override CustomFileWriter CreateWriter()
    {
        return new CustomFileWriter(ConfigurationFile, indentationFactor: 2, commentPrefix: "#");
    }

    public override IEnumerable<string> GeneratedFiles =>
        base.GeneratedFiles.Select(x => {
            var fileName = Path.GetFileName(x).Replace($".{suffix}.yml", $".{suffix}.nuke.yml");
            return $"{Path.GetDirectoryName(x)}\\{AzurePipelineYamlFolder}\\{fileName}";
        });
}

jussimattila avatar Apr 04 '20 08:04 jussimattila

Issue submitted based on this Slack thread: https://nukebuildnet.slack.com/archives/C9Q99MFU0/p1585906090420700

jussimattila avatar Apr 04 '20 08:04 jussimattila

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Apr 25 '20 07:04 lock[bot]