azureazure-devopsazure-pipelines

How to use an Azure Devops Release task to execute a Azure Pipeline


Hey guys please I have a Azure Devops Pipeline configured. I need to create a Azure DevOps Release to run this pipeline... which kind of task should I choose from the list?

I've created a Azure DevOps Release but I cannot find the appropriate task to link to my existing Pipeline


Solution

  • In the release pipeline, you can use the Invoke REST API task to call the REST API "Runs - Run Pipeline" to trigger a YAML pipeline or classic build pipeline.

    1. Go to Project Settings > Service connections to create a Generic service connection.

      • Server URL: The prefix of the REST API URI. You can set it as "https://dev.azure.com/{organization}". Replace {organization} with the actual name of your Azure DevOps organization.

      • Service connection name: Enter a custom name of the service connection.

      enter image description here

    2. Go the release pipeline, add the following things.

      • Add an Agentless job. You can set condition on this job so that the job can run only when the condition is met.

      • Add an Invoke REST API task in the Agentless job.

      enter image description here

    3. On the Invoke REST API task, set the following configurations.

      • Display name: You can set a custom name of the step.

      • Connection type: Generic

      • Generic service connection: The name of the Generic service connection created previously.

      • Method: POST

      • Headers: A JSON content to set the request headers of the API call.

        {
        "Content-Type":"application/json", 
        "Authorization": "Bearer $(system.AccessToken)"
        }
        
      • Body: A JSON content to set the Request Body of the API call. For example.

        // Overwrite the default values of a parameter and a pipeline variable when triggering the pipeline.
        
        {
            "variables": {
                "myVar02": {
                    "value": "4444"
                }
            },
            "templateParameters": {
                "myPara01": "1111"
            }
        }
        
      • URL suffix and parameters: The suffix of the REST API URI. It will combine with the prefix set in the service connection to get the full REST API URI. You can set it as "/{project}/_apis/pipelines/{pipelineId}/runs?api-version=7.0". Replace {project} and {pipelineId} with you actual values.

    With this method, you do not need an agent jobs to trigger the pipeline. So, do not need to wait an available agent in your Azure DevOps organization. The Agentless job can run more quickly than the agent job.