コード例 #1
0
        private async Task <BuildDefinition> CreateDefinitionAsync(string definitionName, SdkComponent component, CancellationToken cancellationToken)
        {
            var sourceRepository = await Context.GetSourceRepositoryAsync(cancellationToken);

            var buildRepository = new BuildRepository()
            {
                DefaultBranch = Context.Branch,
                Id            = sourceRepository.Id,
                Name          = sourceRepository.FullName,
                Type          = "GitHub",
                Url           = new Uri(sourceRepository.Properties["cloneUrl"]),
            };

            buildRepository.Properties.AddRangeIfRangeNotNull(sourceRepository.Properties);

            var projectReference = await Context.GetProjectReferenceAsync(cancellationToken);

            var agentPoolQueue = await Context.GetAgentPoolQueue(cancellationToken);

            var normalizedRelativeYamlPath = component.RelativeYamlPath.Replace("\\", "/");

            var definition = new BuildDefinition()
            {
                Name       = definitionName,
                Project    = projectReference,
                Path       = Context.DevOpsPath,
                Repository = buildRepository,
                Process    = new YamlProcess()
                {
                    YamlFilename = normalizedRelativeYamlPath
                },
                Queue = agentPoolQueue
            };

            if (!Context.WhatIf)
            {
                Logger.LogDebug("Creating definition named '{0}'.", definitionName);

                var buildClient = await Context.GetBuildHttpClientAsync(cancellationToken);

                definition = await buildClient.CreateDefinitionAsync(
                    definition : definition,
                    cancellationToken : cancellationToken
                    );

                Logger.LogInformation("Created definition '{0}' at: {1}", definitionName, definition.GetWebUrl());
            }
            else
            {
                Logger.LogWarning("Skipping creating definition '{0}' (--whatif).", definitionName);
            }

            return(definition);
        }
コード例 #2
0
        private async Task <BuildDefinition> CreateDefinitionAsync(string definitionName, SdkComponent component, CancellationToken cancellationToken)
        {
            var serviceEndpoint = await Context.GetServiceEndpointAsync(cancellationToken);

            var repository = Context.Repository;

            var buildRepository = new BuildRepository
            {
                DefaultBranch = Context.Branch,
                Id            = repository,
                Name          = repository,
                Type          = "GitHub",
                Url           = new Uri($"https://github.com/{repository}.git"),
                Properties    = { ["connectedServiceId"] = serviceEndpoint.Id.ToString() }
            };

            var projectReference = await Context.GetProjectReferenceAsync(cancellationToken);

            var agentPoolQueue = await Context.GetAgentPoolQueue(cancellationToken);

            var normalizedRelativeYamlPath = component.RelativeYamlPath.Replace("\\", "/");

            var definition = new BuildDefinition()
            {
                Name       = definitionName,
                Project    = projectReference,
                Path       = Context.DevOpsPath,
                Repository = buildRepository,
                Process    = new YamlProcess()
                {
                    YamlFilename = normalizedRelativeYamlPath
                },
                Queue = agentPoolQueue
            };

            if (!Context.WhatIf)
            {
                Logger.LogDebug("Creating definition named '{0}'.", definitionName);

                var buildClient = await Context.GetBuildHttpClientAsync(cancellationToken);

                definition = await buildClient.CreateDefinitionAsync(
                    definition : definition,
                    cancellationToken : cancellationToken
                    );

                Logger.LogInformation("Created definition '{0}' at: {1}", definitionName, definition.GetWebUrl());
            }
            else
            {
                Logger.LogWarning("Skipping creating definition '{0}' (--whatif).", definitionName);
            }

            return(definition);
        }