I create 2 YAML pipelines for each of my repos in Azure DevOps using the REST API.
The pipeline works, except that it won't trigger on repo changes. Somehow the pipelines are not fully recognized be Azure DevOps. This means that even when the default azure-pipelines.yml file is used by a REST-created pipeline, the button "Set up build" is still displayed on the repo page.
Also, when I go to Pipelines to set up extra pipelines manually, I cannot do that. It wants to create a new pipeline for the azure-pipelines.yml file (even though it is already used by a REST-created pipeline) and does not allow me to pick a different .yml file.
Here is the code I use to create my pipelines with the REST API:
string pipelinesURL = $"https://dev.azure.com/{ViewModel.Organization}/{ViewModel.ProjectName}/_apis/pipelines?api-version=6.0-preview.1";
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", "", pat))));
string folderToUse = "null";
if (!string.IsNullOrEmpty(folder))
{
folderToUse = "\"" + folder + "\""; //folder + "/"; // @"/" + folder;
}
string pipelineDef =
"{" +
$" \"folder\": {folderToUse}," +
$" \"name\": \"{name}\"," +
" \"configuration\": {" +
" \"type\": \"yaml\"," +
$" \"path\": \"{yamlPath}\"," +
" \"repository\": {" +
$" \"id\": \"{repoId}\"," +
$" \"name\": \"{repoName}\"," +
" \"type\": \"azureReposGit\"" +
" }" +
" }" +
"}";
StringContent stringContent = new StringContent(pipelineDef, Encoding.UTF8, "application/json");
string url = pipelinesURL;
using (HttpResponseMessage response = await client.PostAsync(
url, stringContent))
{
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
return true;
}
}
How do I fix the problem?