我想通过Webhook触发Azure devops管道。
例如,我希望能够使用某些JSON将POST发送到Azure的某个终结点,然后让该终结点触发管道调用以将其传递给JSON。
这可能吗?
答案 0 :(得分:1)
现在可在 Azure DevOps Services 上使用:Generic webhook based triggers for YAML pipelines
请求 URL 将如下所示:
https://dev.azure.com/<orgName>/_apis/public/distributedtask/webhooks/<WebHook Name>?api-version=6.0-preview
答案 1 :(得分:0)
有可能。 You can find the documentation here。
有关更多详细信息,请参见以下答案:stackoverflow.com/a/59857117/5225577
POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=5.0
必填字段是项目,组织和api版本。可选参数允许您自定义构建的性质,例如传入构建的源代码或签到票证。
答案 2 :(得分:0)
通过webhook触发天青管道吗?
我同意4c74356b41。
我认为没有真正的webbhook支持。 AFAIK,Webhook通常不支持POST
数据,它仅显示一个简单的Get
。
您可以在github上查看有关此问题的类似线程以获取更多详细信息:
Triggering a build from a webhook
希望这会有所帮助。
答案 3 :(得分:0)
为了使用 REST API 调用对构建进行排队,您可以向以下 URI 发送 POST 请求:
POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?definitionId={definitionId}&api-version=6.0
您只需在 Azure DevOps 中打开该特定管道即可获取定义 ID。页面的 URL 包含如下所示的 definitionId:
https://dev.azure.com/{organization}/{project}/_build?definitionId=1&_a=summary
。在本例中,definitionId 为 1。您的请求的标头应包含范围为 vso.build_execute
vso.build_execute - 授予访问构建工件的能力,包括构建结果、定义和请求,以及对构建进行排队、更新构建属性的能力,以及通过服务挂钩接收有关构建事件的通知的能力。< /p>
Curl 中的以下请求将如下所示:
curl -X POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?definitionId=1&api-version=6.0 -H "Authorization: Basic <Personal-Access-Token>" -H "Content-Type: application/json" -H "Content-Length: 0"
Python 中的以下请求将如下所示:
import requests
from requests.structures import CaseInsensitiveDict
url = "https://dev.azure.com/{organization}/{project}/_apis/build/builds?definitionId=1&api-version=6.0"
headers = CaseInsensitiveDict()
headers["Authorization"] = "Basic <Personal-Access-Token>"
headers["Content-Type"] = "application/json"
headers["Content-Length"] = "0"
resp = requests.post(url, headers=headers)
print(resp.status_code)
Java 中的以下请求将如下所示:
URL url = new URL("https://dev.azure.com/{organization}/{project}/_apis/build/builds?definitionId=1&api-version=6.0");
HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setRequestMethod("POST");
http.setDoOutput(true);
http.setRequestProperty("Authorization", "Basic <Personal-Access-Token>");
http.setRequestProperty("Content-Type", "application/json");
http.setRequestProperty("Content-Length", "0");
System.out.println(http.getResponseCode() + " " + http.getResponseMessage());
http.disconnect();
C#/.NET 中的以下请求将如下所示:
var url = "https://dev.azure.com/{organization}/{project}/_apis/build/builds?definitionId=1&api-version=6.0";
var httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.Method = "POST";
httpRequest.Headers["Authorization"] = "Basic <Personal-Access-Token>";
httpRequest.ContentType = "application/json";
httpRequest.Headers["Content-Length"] = "0";
var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
Console.WriteLine(httpResponse.StatusCode);
Powershell 中的以下请求将如下所示:
$Header = @{
"authorization" = "Basic <Personal-Access-Token>"
}
$Parameters = @{
Method = "POST"
Uri = "https://dev.azure.com/{organization}/{project}/_apis/build/builds?definitionId=1&api-version=6.0"
Headers = $Header
ContentType = "application/json"
}
Invoke-RestMethod @Parameters