示例#1
0
        public async Task <BuildDefinition> CreatePipeline(string name, string projectName, string repositoryName, string filename, string folderPath)
        {
            BuildDefinition definition = new BuildDefinition
            {
                Name        = name,
                Description = $"A pipeline for {name} based on {filename}"
            };

            BuildRepository repository = new BuildRepository
            {
                Name          = repositoryName,
                Type          = "tfsgit",
                DefaultBranch = "master"
            };

            definition.Repository = repository;
            definition.Path       = folderPath;

            var process = new YamlProcess
            {
                YamlFilename = filename
            };

            definition.Process = process;

            definition.Queue = new AgentPoolQueue
            {
                Id = await GetAgentQueueByHeuristic(projectName)
            };

            ContinuousIntegrationTrigger ciTrigger = new ContinuousIntegrationTrigger();

            ciTrigger.SettingsSourceType = 2;
            definition.Triggers.Add(ciTrigger);

            BuildDefinition pipeline = null;

            try
            {
                pipeline = await Build.CreateDefinitionAsync(definition, projectName);
            }
            catch (DefinitionExistsException)
            {
                pipeline = await GetPipeline(projectName, name);
            }

            return(pipeline);
        }
示例#2
0
        /// <summary>
        /// Create build definition based on yaml file
        /// </summary>
        /// <param name="TeamProjectName"></param>
        static void CreateYamlBuild(string TeamProjectName)
        {
            string BuildName     = "NewBuildDef";
            string BuildPath     = "Cloned";
            string GitRepoName   = "YamlBuildDefRepo";
            string GitRepoFormat = @"https://<org>@dev.azure.com/<org>/{0}/_git/{1}"; // link to clone a git repo
            string RepoBranch    = "refs/heads/master";                               // example for branch dev: refs/heads/dev
            string SlnPath       = "New Folder/New project.sln";

            BuildDefinition newBuild = new BuildDefinition();

            newBuild.Path  = BuildPath;
            newBuild.Name  = BuildName;
            newBuild.Queue = new AgentPoolQueue()
            {
                Name = "Hosted VS2017"
            };

            YamlProcess yamlProcess = new YamlProcess();

            yamlProcess.YamlFilename = "<yaml file>";
            newBuild.Process         = yamlProcess;

            newBuild.Repository               = new BuildRepository();
            newBuild.Repository.Url           = new Uri(String.Format(GitRepoFormat, TeamProjectName, GitRepoName));
            newBuild.Repository.Name          = GitRepoName;
            newBuild.Repository.DefaultBranch = RepoBranch;
            newBuild.Repository.Type          = RepositoryTypes.TfsGit;

            newBuild.Variables.Add("BuildConfiguration", new BuildDefinitionVariable {
                AllowOverride = false, IsSecret = false, Value = "Debug"
            });
            newBuild.Variables.Add("BuildPlatform", new BuildDefinitionVariable {
                AllowOverride = false, IsSecret = false, Value = "Any CPU"
            });
            newBuild.Variables.Add("Parameters.solution", new BuildDefinitionVariable {
                AllowOverride = false, IsSecret = false, Value = SlnPath
            });

            newBuild = BuildClient.CreateDefinitionAsync(newBuild, TeamProjectName).Result;

            Console.WriteLine("The build definition has been created");
            Console.WriteLine("Build Id: {0}\nBuild Name: {1}\n Build Path: {2}", newBuild.Id, newBuild.Name, newBuild.Path);
        }
        private async Task <bool> SearchForTaskInYamlDefinition(IList <Guid> taskIds, YamlProcess yamlProcess, string repositoryId)
        {
            if (string.IsNullOrEmpty(yamlProcess.YamlFilename))
            {
                return(false);
            }

            var safeYamlFileName = GetYamlFileName(yamlProcess.YamlFilename);

            var searchResults = await CodeSearchForYamlFile(safeYamlFileName);

            string yamlFileContent = default;

            if (searchResults.Count() > 0)
            {
                yamlFileContent = await GetYamlFileFromRepository(searchResults, repositoryId);

                if (string.IsNullOrEmpty(yamlFileContent))
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            return(DoesYamlContainsTask(taskIds, yamlFileContent) ? true : false);
        }