Exemplo n.º 1
0
        public override void Write(CustomFileWriter writer)
        {
            if (VariableGroups.Length > 0)
            {
                using (writer.WriteBlock("variables:"))
                {
                    VariableGroups.ForEach(x => writer.WriteLine($"- group: {x}"));
                    writer.WriteLine();
                }
            }

            if (VcsPushTrigger != null)
            {
                using (writer.WriteBlock("trigger:"))
                {
                    VcsPushTrigger.Write(writer);
                    writer.WriteLine();
                }
            }

            using (writer.WriteBlock("stages:"))
            {
                Stages.ForEach(x => x.Write(writer));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            VariableGroups groups = await GetVariableGroupsAsync(_config.GetValue <string>("AzureDevOps:Organisation"), _config.GetValue <string>("AzureDevOps:ProjectName"));

            var viewModel = new HomeViewModel();

            viewModel.AllVariableGroups = groups.value.ToDictionary(x => x.id, x => x.name);

            return(View(viewModel));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Index(HomeViewModel model)
        {
            VariableGroups groups = await GetVariableGroupsAsync(_config.GetValue <string>("AzureDevOps:Organisation"), _config.GetValue <string>("AzureDevOps:ProjectName"));

            model.AllVariableGroups = groups.value.ToDictionary(x => x.id, x => x.name);

            model.VariableGroupAppearsInBuildPipelines = await BuildsThatUseVariableGroupAsync(model.SelectedVariableGroupId);

            model.VariableGroupAppearsInReleasePipelines = await ReleasesThatUseVariableGroupAsync(model.SelectedVariableGroupId);

            return(View(model));
        }
Exemplo n.º 4
0
        public static async Task <VariableGroups> GetVariableGroupsAsync()
        {
            try
            {
                var jsonText = await ExecuteJsonAsync(string.Format("https://dev.azure.com/{0}/{1}/_apis/distributedtask/variablegroups", Properties.Settings.Default.Organisation, Properties.Settings.Default.ProjectName));

                VariableGroups vGroups = JsonConvert.DeserializeObject <VariableGroups>(jsonText);
                return(vGroups);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw;
            }
        }
Exemplo n.º 5
0
        public void FromXml(string xml)
        {
            try
            {
                // and use LINQ to parse it back out
                XDocument doc = XDocument.Parse(xml);

                XElement filter = doc
                                  .Element("RunningTotalsTask")
                                  .Element("FilterSettings");
                FilterSettings = new FilterSettings(filter.Value);

                XElement outdata = doc
                                   .Element("RunningTotalsTask")
                                   .Element("DataOut");
                DataOut = outdata.Value;

                XElement measure = doc
                                   .Element("RunningTotalsTask")
                                   .Element("MeasureVar");

                VariableMeasure = measure.Value;

                XElement totals = doc
                                  .Element("RunningTotalsTask")
                                  .Element("TotalsVar");

                VariableTotal = totals.Value;

                XElement groups = doc
                                  .Element("RunningTotalsTask")
                                  .Element("GroupVariables");

                var g = groups.Elements("GroupVariable");
                foreach (XElement e in g)
                {
                    VariableGroups.Add(e.Value);
                }
            }
            catch (XmlException)
            {
                // couldn't read the XML content
            }
        }
Exemplo n.º 6
0
        public static async Task GetUnusedVariableGroups()
        {
            VariableGroups vGroups = await GetVariableGroupsAsync();

            ReleaseDefinitions releaseDefinitions = await GetReleaseDefinitionsAsync();

            List <VariableGroupsValue> groups = vGroups.value;
            List <int> usedGroups             = new List <int>();

            foreach (ReleaseDefinition rDef in releaseDefinitions.value)
            {
                Release release = await GetRelease(rDef.id);

                foreach (int variablegroupId in release.variableGroups)
                {
                    var g = groups.Find(x => x.id == variablegroupId);
                    if (g == null)
                    {
                        Console.WriteLine(string.Format("{0} is referencing a deleted variable group (id-{1})", rDef.name, variablegroupId));
                    }
                    else
                    {
                        usedGroups.Add(variablegroupId);
                    }
                }
                foreach (Environment environment in release.environments)
                {
                    foreach (int variablegroupId in environment.variableGroups)
                    {
                        var g = groups.Find(x => x.id == variablegroupId);
                        if (g == null)
                        {
                            Console.WriteLine(string.Format("{0} is referencing a deleted variable group (id-{1})", rDef.name, variablegroupId));
                        }
                        else
                        {
                            usedGroups.Add(variablegroupId);
                        }
                    }
                }
            }

            BuildDefinitions buildDefinitions = await GetBuildDefinitionsAsync();

            foreach (var buildDefinition in buildDefinitions.value)
            {
                Build build = await GetBuild(buildDefinition.id);

                if (build.variableGroups != null)
                {
                    foreach (VariableGroup variablegroup in build.variableGroups)
                    {
                        var g = groups.Find(x => x.id == variablegroup.id);
                        if (g == null)
                        {
                            Console.WriteLine(string.Format("{0} is referencing a deleted variable group (id-{1})", buildDefinition.name, variablegroup.id));
                        }
                        else
                        {
                            usedGroups.Add(variablegroup.id);
                        }
                    }
                }
            }

            bool used;

            foreach (var variableGroup in vGroups.value)
            {
                used = false;
                foreach (var usedGroup in usedGroups)
                {
                    if (variableGroup.id == usedGroup)
                    {
                        used = true;
                    }
                }
                if (used == false)
                {
                    Console.WriteLine(String.Format("'{0}' is not used - id {1}", variableGroup.name, variableGroup.id));
                }
            }
        }