Search code examples
pythonazure-functionsazure-logic-appsazure-devops-rest-apiazure-devops-pipelines

Trigger an Azure Devops pipeline from an azure function using python


I have an existing Devops pipeline that trains ML models. 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. will It collect the new data, apply the data pre-processing and finally trigger the Azure Devops training pipeline. 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. I founded this python git repo https://github.com/microsoft/azure-devops-python-api which provides an API to communicate with Azure DevOps. I executed the code provided by this package which displays the list of my devops projects. 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 ? PS: I am using a python 3.9 Timer Trigger Azure function. Thank you in advance for your help.

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. Above the workflow that I created: enter image description here

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. But navigating in the different actions under the devops service, I cannot found any thing related to launching a devops pipeline. Can anyone have an idea how to do it.


Solution

  • Thanks to the tips provided by @Mohammed I found a solution. Logic App provides what I am looking for. 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. This is my first experiment architecture and I will update it later by adding Azure Function service before calling the Devops Pipeline. enter image description here