azure devops c# dotnet core sdk - creating build definition / pipeline for your repository.
Creating azure devops build definition can be challenging due to the large options that is available. Below is the most basic code sample that you can use the successfully create a build definition (essentially a pipeline) for your repository.
Please note: You might get into other issues like invalid service connection, etc. Really depends on what you specify in the build definitions. Suggest that you make incremental changes.
Here is the code base.
var _azureGitClient = connection.GetClient<BuildHttpClient>();
var buildDefinition = new BuildDefinition
{
Name = "My New Build Definition",
Project = new TeamProjectReference { Name = projectName, Id = repo.ProjectReference.Id },
Repository = new BuildRepository
{
Type = RepositoryTypes.TfsGit,
Name = "name-of-your-repository",
Url = new Uri($"https://dev.azure.com/<your-org>/<your-project/_git/<your-repo-name>")
},
Queue = new AgentPoolQueue { Name = "Default" },
};
YamlProcess yamlProcess = new YamlProcess();
yamlProcess.YamlFilename = "azure-pipeline.yaml";
buildDefinition.Process = yamlProcess;
var result = await _azureGitClient.CreateDefinitionAsync(buildDefinition, "your-project");
For other task, you can easily find more information here:
https://github.com/microsoft/azure-devops-dotnet-samples/tree/main/ClientLibrary/Samples
Comments