jan*_*pio 8 azure-devops azure-pipelines azure-devops-rest-api
我想通过API调用自动化Azure管道的排队,获取有关管道/构建/作业状态的信息,
Azure Pipelines文档仅针对“调用HTTP Rest API”任务提及“ API”:https : //docs.microsoft.com/zh-cn/azure/devops/pipelines/tasks/utility/http-rest-api?view= vsts这可能会派上用场,但不是我想要的。
有一个“ Azure DevOps Services REST API”:https ://docs.microsoft.com/zh-cn/rest/api/azure/devops/?view=azure-devops-rest-5.1 但我找不到任何提到“管道”,所以这似乎也不是对的。
StackOverflow标记azure-devops-rest-api也仅提及VSTS和TFS:
Visual Studio Team Services REST API是一组API,允许管理Visual Studio Team Services帐户以及TFS 2015和2017服务器。
除了这两个结果,我只找到这些版本的其他副本或其他版本的翻译-以及许多与Azure无关的文档。
我只是使用错误的单词进行搜索吗?
是否有适用于Azure DevOps管道的实际API?
它有可用的API资源管理器吗?
它是否具有适用于JavaScript,Ruby或PHP等语言的客户端?
jan*_*pio 10
似乎我不擅长使用Google搜索:
通过API触发Azure Pipelines构建并开始构建并通过VSTS Rest API(通过[azure-pipelines] api在StackOverflow 上进行搜索找到)传递变量,这使我想到了我上面提到的Azure DevOps Services REST API。
我也一直致力于自动化 DevOps 管道,并继续回到这里。其中一些信息似乎已经过时。截至我撰写本文时,我相信Microsoft 文档中的这篇文章是最新的。我确实得绞尽脑汁才能让它工作,但最终得到了这段代码
public static async Task InitiatePipeline(CancellationToken cancellationToken = default)
{
using(HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var token = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", AppSettings.DevOpsPAT)));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", token);
var repoGuid = "Put GUID Here"; // You can get GUID for repo from the URL when you select the rpo of interest under Repos is Project Settings
var bodyJson = @"{
""parameters"": {
""parameterName"": ""parameterValue""
},
""variables"": {},
""resources"": {
""repositories"": {
""self"": {
""repository"": {
""id"": """ + repoGuid + @""",
""type"": ""azureReposGit""
},
""refName"": ""refs/heads/master""
}
}
}
}";
var bodyContent = new StringContent(bodyJson, Encoding.UTF8, "application/json");
var pipeLineId = 61; // Can get this from URL when you open the pipeline of interest in Azure DevOps
var response = await client.PostAsync($"https://dev.azure.com/ORG_NAME/PROJECT_NAME/_apis/pipelines/{pipeLineId}/runs?api-version=6.0-preview.1", bodyContent, cancellationToken);
response.EnsureSuccessStatusCode();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4194 次 |
| 最近记录: |