如何编写azure函数来触发azure devops管道?这可能吗?
我正在尝试设置一个Azure函数,该函数可以触发Azure devops构建管道。但我不确定如何进行,甚至不确定是否有可能这样做 我已经准备好使用构建管道,但是Azure devops已经提供的传统触发器无法使用。我不能透露原因,但我需要使用Azure函数触发它。这方面的任何帮助都会非常有用如何编写azure函数来触发azure devops管道?这可能吗?,azure,azure-devops,azure-functions,Azure,Azure Devops,Azure Functions,我正在尝试设置一个Azure函数,该函数可以触发Azure devops构建管道。但我不确定如何进行,甚至不确定是否有可能这样做 我已经准备好使用构建管道,但是Azure devops已经提供的传统触发器无法使用。我不能透露原因,但我需要使用Azure函数触发它。这方面的任何帮助都会非常有用 谢谢。您可以简单地使用Azure DevOps的REST API,并从您的函数调用这些API。请参见此处:如何进行此操作,以及是否有可能进行此操作。 当然,可以通过Azure函数触发Azure Devops
谢谢。您可以简单地使用Azure DevOps的REST API,并从您的函数调用这些API。请参见此处:如何进行此操作,以及是否有可能进行此操作。 当然,可以通过Azure函数触发Azure Devops管道 为了实现这一点,您还将使用Visual Studio,最好使用2017版或更高版本,并安装.Net Core SDK和
.cs
文件并在其中输入以下脚本:
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
namespace PartsUnlimited.AzureFunction
{
public static class Function1
{
[FunctionName("HttpTriggerCSharp1")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route =
null)]HttpRequestMessage req, TraceWriter log)
{
var userIdKey = req.GetQueryNameValuePairs().FirstOrDefault(q =>
string.Equals(q.Key, "UserId", StringComparison.OrdinalIgnoreCase));
var userId = string.IsNullOrEmpty(userIdKey.Value) ? int.MaxValue : Convert.ToInt64(userIdKey.Value);
var url = $"https://<<APIAppServiceUrl>>/api/{(userId > 10 ? "v1" : "v2")}/specials/GetSpecialsByUserId?id={userId}";
using (HttpClient httpClient = new HttpClient())
{
return await httpClient.GetAsync(url);
}
}
}
}
使用系统;
使用System.Linq;
Net系统;
使用System.Net.Http;
使用System.Threading.Tasks;
使用Microsoft.Azure.WebJobs;
使用Microsoft.Azure.WebJobs.Extensions.Http;
使用Microsoft.Azure.WebJobs.Host;
命名空间PartsUnlimited.AzureFunction
{
公共静态类函数1
{
[函数名(“HttpTriggerCSharp1”)]
公共静态异步任务运行([HttpTrigger(AuthorizationLevel.Function),“get”,“post”,Route=
null)]HttpRequestMessage请求,TraceWriter日志)
{
var userIdKey=req.GetQueryNameValuePairs().FirstOrDefault(q=>
等于(q.Key,“UserId”,StringComparison.OrdinalIgnoreCase);
var userId=string.IsNullOrEmpty(userIdKey.Value)?int.MaxValue:Convert.ToInt64(userIdKey.Value);
var url=$”https://<这是由我们的Azure DevOps实验室编写的,它有详细的步骤,您可以参考。REST API可以很容易地从Azure函数调用
您几乎可以使用azure DevOps部署整个基础架构,也可以仅基于函数调用部署代码
有关更多信息,请参阅: