How to proceed with this and if it's even possible to do so.
Of course, it can do to trigger a Azure Devops pipeline by Azure function.
To achieve this, you will use Visual Studio also, better with the version 2017 or higher , and also installed .Net Core SDK and Develop Azure Functions using Visual Studio.
- In the Azure Function App you created, open HttpTrigger1, and
click Get Function Url. This is a key point, so better save
it in the txt. Because as this execution, Azure Function just act as
a switching proxy or mechanism.
Create a Azure Function project in Visual studio. In template,
choose HttpTrigger template, Azure Functions v1 (.NET
Framework) from the framework dropdown.
Open .cs
file and input the below script in it:
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);
}
}
}
}
Replace <<APIAppServiceUrl>>
with your AzureWebsite.net URL.
Go xxxxWebsite->Controllers->StoreController.cs, replace the url
variable in line 46 with your Function url which copied in Step 1.
Click Commit and Push All to push the changes to the Azure
Devops repository.
Create a build pipeline, and enable CI. And also, create release pipeline, add deloy Azure App task and enable CD.
That's all the steps you need to create. There has been a blog which written by our Azure DevOps Labs and it has the detailed steps, you can refer to it.