Пример #1
0
    public void GetRegionSequence_ForAllEnvironments(DeploymentEnvironment env, DeploymentRegion source, DeploymentRegion[] expected)
    {
        var ret = EswDevOpsSdk.GetRegionSequence(env, source);

        ret.Should().ContainInOrder(expected).And.HaveCount(expected.Length);
    }
Пример #2
0
        private async Task CustomizeNonRingPipeline(VstsReleaseDefinition model, ReleaseDefinition pipeline)
        {
            //load sf endpoints
            var connectionEndpoints =
                await _taskAgentHttpClient.GetServiceEndpointsAsync(_vstsConfiguration.VstsTargetProjectId);

            //set up source trigger
            var sourceTrigger = (ArtifactSourceTrigger)pipeline.Triggers.First();

            sourceTrigger.ArtifactAlias = model.BuildDefinition.ToString();

            var clonedEnvStages = new List <ReleaseDefinitionEnvironment>();

            var rank = 1;

            //relink to target build definition
            foreach (var e in pipeline.Environments)
            {
                if (!Enum.TryParse(e.Name, true, out DeploymentEnvironment sierraEnvironment))
                {
                    throw new Exception($"Release template #{pipeline.Id} contains unrecognized environment - {e.Name}");
                }

                if (model.SkipEnvironments != null && model.SkipEnvironments.Contains(sierraEnvironment))
                {
                    continue;
                }

                ReleaseDefinitionEnvironment predecessor = null;

                foreach (var r in EswDevOpsSdk.GetRegionSequence(sierraEnvironment, default))
                {
                    var regionEnv = e.DeepClone();
                    var phase     = regionEnv.DeployPhases.First();
                    var envInput  = (AgentDeploymentInput)phase.GetDeploymentInput();
                    envInput.ArtifactsDownloadInput.DownloadInputs.First().Alias = model.BuildDefinition.ToString();

                    regionEnv.Name = $"{e.Name} - {r}";
                    regionEnv.Rank = rank++;
                    regionEnv.Id   = regionEnv.Rank;
                    //link condition to predecessor (region)
                    if (predecessor != null)
                    {
                        regionEnv.Conditions = new List <Condition>(new[]
                        {
                            new Condition(predecessor.Name, ConditionType.EnvironmentState,
                                          "4" /*find the documentation for this value*/)
                        });
                    }

                    //re-point to correct SF instance
                    var sfDeployStep =
                        phase.WorkflowTasks.FirstOrDefault(t => t.TaskId == Guid.Parse(VstsSfDeployTaskId));

                    if (sfDeployStep == null)
                    {
                        throw new Exception(
                                  $"Release template #{pipeline.Id} does not contain expected Task {VstsSfDeployTaskId} for {e.Name} environment");
                    }

                    var expectedConnectionName =
                        $"esw-{r.ToRegionCode().ToLowerInvariant()}-fabric-{e.Name.ToLowerInvariant()}";

                    var sfConnection = connectionEndpoints.FirstOrDefault(c => c.Name == expectedConnectionName);
                    if (sfConnection == null)
                    {
                        throw new Exception(
                                  $"SF Endpoint {expectedConnectionName} not found in VSTS project {_vstsConfiguration.VstsTargetProjectId}");
                    }

                    sfDeployStep.Inputs[VstsSfDeployTaskConnectionNameInput] = sfConnection.Id.ToString();

                    //set region in manifest
                    var sfUpdaterStep =
                        phase.WorkflowTasks.FirstOrDefault(t => t.TaskId == Guid.Parse(VstsSfUpdateTaskId));

                    if (sfUpdaterStep == null)
                    {
                        throw new Exception(
                                  $"Release template {pipeline.Name} does not contain expected Task {VstsSfUpdateTaskId} for {e.Name} environment");
                    }

                    sfUpdaterStep.Inputs[VstsSfUpdateTaskRegionInput] = r.ToRegionName();

                    clonedEnvStages.Add(regionEnv);
                    predecessor = regionEnv;
                }
            }

            pipeline.Environments = clonedEnvStages;

            //set tenant specific variables
            pipeline.Variables["TenantCode"].Value = model.TenantCode;
            pipeline.Variables["PortNumber"].Value = "11111"; //TODO: link to port management
        }