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!

How get the variable configuration for custom variable with an action?



  • Within my custom extension I often have the need to refer to the properties set via the editor for my ArtifactoryVersionVariable within actions, predicates, etc. Is there a better way to get this or is parsing the xml as I'm doing below as good as it gets?

    internal static ArtifactoryVersionVariable GetVariableDeclaration(int applicationId, string artifactoryVariableName)
    {
        // Get variable properties
        var settings = StoredProcs
                 .Variables_GetVariableDeclarations("B", applicationId, null)
                 .Execute()
                 .Where(s => s.Variable_Name == artifactoryVariableName)
                 .FirstOrDefault()
                 .Variable_Configuration;
    
        XmlDocument xml = new XmlDocument();
        xml.LoadXml(settings);
    
        return new ArtifactoryVersionVariable
        {
            RepositoryKey = xml.SelectSingleNode("//Properties/@RepositoryKey").Value,
            RepositoryPath = xml.SelectSingleNode("//Properties/@RepositoryPath").Value,
            Filter = xml.SelectSingleNode("//Properties/@Filter").Value,
            TrimFromPath = xml.SelectSingleNode("//Properties/@TrimFromPath").Value,
            ReplaceSlashWithDot = bool.Parse(xml.SelectSingleNode("//Properties/@ReplaceSlashWithDot").Value),
            DefaultToNotIncluded = bool.Parse(xml.SelectSingleNode("//Properties/@DefaultToNotIncluded").Value)
        };
    }
    

    Product: BuildMaster
    Version: 4.6.4



  • Anything with the suffix _Configuration can be deserialized, so for your example all you need is:

    return (ArtifactoryVersionVariable)Util.Persistence
               .DeserializeFromPersistedObjectXml(settings);

Log in to reply
 

Inedo Website HomeSupport HomeCode of ConductForums GuideDocumentation