Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.

If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!

Do not overwrite build artifacts



  • We have a need to avoid recreating build artifacts on re-executions if they already exist. I have tried a few ideas, but I have run into issues and questions with each route.

    1. Use a predicate to just skip the "create artifact" peace on re-execution. No question here, it just doesn't quite meet the requirements. If a build fails before the artifact is created, re-execution should create it.
    2. Use a variable to track whether an artifact is created. I tried a build-level variable with a default value of "false", but it seems that the variable gets set back to the default value on every execution. If I don't set a default value it works, but I'm forced to type "false" into a text box when I create the build. Is this intended behavior or a bug?
    3. Create a custom predicate to check whether a build artifact exists. This seems like the most promising option so far, but I don't see an obvious way to check artifacts through the IActionExecutionContext that's passed in to the Evaluate method. Is there any way to get the list of build artifacts from a custom predicate?

    Thanks,

    Tim

    Product: BuildMaster
    Version: 4.4.6



  • Option 3 is the way to go (until we add this to BuildMaster's core at least):

    using System;
    using Inedo.BuildMaster;
    using Inedo.BuildMaster.Data;
    using Inedo.BuildMaster.Extensibility.Actions;
    using Inedo.BuildMaster.Extensibility.Agents;
    using Inedo.BuildMaster.Extensibility.Predicates;
    
    namespace CustomExtension
    {
        [Serializable]
        [PredicateProperties(
            "Artifact Does Not Exist",
            "Evaluates whether a specified artifact exists on disk.")]
        public sealed class ArtifactExistsPredicate : PredicateBase
        {
            [Persistent]
            public string ArtifactName { get; set; }
    
            public override bool Evaluate(IActionExecutionContext context)
            {
                string artifactsBasePath = StoredProcs.Configuration_GetValue("CoreEx", "ArtifactsBasePath").Execute();
    
                string artifactPath = Util.Artifacts.GetFullArtifactPath(
                    artifactsBasePath,
                    context.ApplicationId, 
                    context.ReleaseNumber, 
                    context.BuildNumber, 
                    context.DeployableId ?? 0, 
                    this.ArtifactName
                  );
    
                using (var agent = Util.Agents.CreateLocalAgent())
                {
                    var fileOps = agent.GetService<IFileOperationsExecuter>();
                    return !fileOps.FileExists(artifactPath);
                }
            }
    
            public override string ToString()
            {
                return string.Format("Artifact {0} does not exist", this.ArtifactName);
            }
        }
    }


  • Thanks Tod, that's exactly what I needed. Works like a charm.

    -Tim



Inedo Website HomeSupport HomeCode of ConductForums GuideDocumentation