Share via

Trigger devops pipeline from azure function

Anonymous
2024-10-23T23:21:45.0966667+00:00

We are trying to trigger a yaml pipeline from azure function. We are using managed identity using federated credential as authentication.

Can you help with what is the "IDENTITY_ENDPOINT" and "IDENTITY_HEADER" to be used for token generation? W see the below error currently.

2024-10-21T23:09:34Z [Error] Error triggering pipeline. Status Code: InternalServerError. Error:

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.


1 answer

Sort by: Most helpful
  1. Pinaki Ghatak 5,695 Reputation points Microsoft Employee
    2024-10-27T20:03:16.99+00:00

    Hello colleague @Anonymous

    To generate a token, you can use the following code snippet:

    import os from azure.identity
    import DefaultAzureCredential from azure.devops.connection
    import Connection 
    
    # Set the IDENTITY_ENDPOINT and IDENTITY_HEADER environment variables 
    os.environ["IDENTITY_ENDPOINT"] = "http://169.254.169.254/metadata/identity/oauth2/token"
    os.environ["IDENTITY_HEADER"] = "X-IDENTITY-HEADER"
    
    # Create a connection to Azure DevOps using the DefaultAzureCredential
    credential = DefaultAzureCredential()
    connection = Connection(base_url="[https://dev.azure.com/{organization}]()", creds=credential)
    
    # Get the pipeline client
    pipeline_client = connection.clients.get_pipeline_client()
    
    # Trigger the pipeline
    response = pipeline_client.run_pipeline(project="{project}", pipeline_id="{pipeline_id}", parameters="{parameters}")
    

    Make sure to replace the {organization}, {project}, {pipeline_id}, and {parameters} placeholders with the appropriate values for your pipeline.

    Also, ensure that the Azure Function has the necessary permissions to trigger the pipeline. Regarding the error you are seeing, InternalServerError typically indicates an issue on the server side. You may want to check the logs for your pipeline to see if there are any errors there.


    I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.