简体   繁体   English

使用 python 从 azure function 触发 Azure Devops 管道

[英]Trigger an Azure Devops pipeline from an azure function using python

I have an existing Devops pipeline that trains ML models.我有一个现有的 Devops 管道来训练 ML 模型。 To guaranty the robustness for the models, it will be necessary to retrain it periodically.为了保证模型的稳健性,有必要定期对其进行重新训练。 For this I decided to create an Azure function that will be executed each month.为此,我决定创建一个每月执行一次的 Azure function。 will It collect the new data, apply the data pre-processing and finally trigger the Azure Devops training pipeline.它将收集新数据,应用数据预处理并最终触发 Azure Devops 培训管道。 All of this must be done with python. By doing a research, I understood that this can be done using REST Azure Devops API request.所有这些都必须用 python 完成。通过研究,我了解到这可以使用 REST Azure Devops API 请求来完成。 I founded this python git repo https://github.com/microsoft/azure-devops-python-api which provides an API to communicate with Azure DevOps.我创建了这个 python git repo https://github.com/microsoft/azure-devops-python-api它提供了一个 API 来与 Azure DevOps 通信。 I executed the code provided by this package which displays the list of my devops projects.我执行了这个 package 提供的代码,它显示了我的 devops 项目列表。 But I can't found how trigger the pipeline.但我找不到如何触发管道。 Assuming that my organisation named ORGA1, the project named PROJ1 and the pipeline that I want ti execute named PIPELINE1, How can I launch it using an Azure function or even a simple python script?假设我的组织名为 ORGA1,项目名为 PROJ1,我要执行的管道名为 PIPELINE1,我如何使用 Azure function 甚至简单的 python 脚本启动它? PS: I am using a python 3.9 Timer Trigger Azure function. Thank you in advance for your help. PS:我使用的是 python 3.9 定时器触发器 Azure function。在此先感谢您的帮助。

EDIT编辑

I tired to use LOGIC APP to do this like @mohammed described in the comment and I think that this is a good solution.我厌倦了像评论中描述的@mohammed 那样使用LOGIC APP来执行此操作,我认为这是一个很好的解决方案。 Above the workflow that I created:在我创建的工作流程上方: 在此处输入图像描述

So I launch the logic app each X hours, this will trigger the azure Devops, and ASA it end training with Success it will send me an email. I have one error here, is that I am creating a new release and not triggering a specific pipeline each time.所以我每隔 X 小时启动一次逻辑应用程序,这将触发 azure Devops,ASA 以成功结束训练,它将向我发送一个 email。我这里有一个错误,是我正在创建一个新版本,而不是触发特定的每次流水线。 But navigating in the different actions under the devops service, I cannot found any thing related to launching a devops pipeline.但是在 devops 服务下的不同操作中导航,我找不到任何与启动 devops 管道相关的东西。 Can anyone have an idea how to do it.任何人都可以知道如何去做。

You can use a Logic App with a timer to trigger your DevOps pipeline instead of an Azure function, as it has all the built-in connectors required to interface with your DevOps.您可以使用带有计时器的逻辑应用程序来触发您的 DevOps 管道,而不是 Azure function,因为它具有与您的 DevOps 交互所需的所有内置连接器。 See: https://www.serverlessnotes.com/docs/keep-your-team-connected-using-azure-devops-and-azure-logic-apps请参阅: https://www.serverlessnotes.com/docs/keep-your-team-connected-using-azure-devops-and-azure-logic-apps

Thanks to the tips provided by @Mohammed I found a solution.感谢@Mohammed 提供的提示,我找到了解决方案。 Logic App provides what I am looking for. Logic App提供了我正在寻找的东西。 Under the list of Devops connectors provided the by the Logic App, there is a connector named Queue a new build and this is exactly what I am looking for.在 Logic App 提供的 Devops 连接器列表下,有一个名为Queue a new build的连接器,这正是我要找的。 This is my first experiment architecture and I will update it later by adding Azure Function service before calling the Devops Pipeline.这是我的第一个实验架构,稍后我将通过在调用 Devops Pipeline 之前添加 Azure Function 服务来更新它。 在此处输入图像描述

You may try using Azure Durable Functions, you can kind of replicate what a Logic App does while still using Azure Functions.您可以尝试使用 Azure 持久函数,您可以在某种程度上复制逻辑应用程序的功能,同时仍然使用 Azure 函数。 See documentation here 1请参阅此处的文档1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM