azure-devopstestautomationfx

Azure devops Release pipeline Trigger


I have set up where we have the Application build release pipeline & test automation release pipeline are separate.Currently whenever there is build created then test automation starts which is wrong as build artifacts are just published but not yet deployed which will be done by the release pipeline. So I am looking for a solution where I can add the trigger to the test release pipeline where It will check build release pipeline is completed & code is deployed to the environment.


Solution

  • According to your description, you have three pipeline, build pipeline(build and publish artifacts), Application release pipeline and test automation release pipeline. You have set up a CD trigger that will trigger the release pipeline together after the pipeline is completed. But the order in which you want the pipeline to run is build pipeline->Application release pipeline->test automation release pipeline, right?

    So I am looking for a solution where I can add the trigger to the test release pipeline where It will check build release pipeline is completed & code is deployed to the environment.

    As a workaround, we need to open test automation release pipeline definition and disable the CD trigger, then open open Application release pipeline, add task power shell at the end of the job and call the REST API to trigger release pipeline(test automation release pipeline).

    Power shell Script:

    $token = "{PAT}"   
    $url = "https://vsrm.dev.azure.com/{Org name}/{Project name}/_apis/Release/releases?api-version=5.0"
    $token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
    
    
    $JSON = @"
    {
      "definitionId": {test automation release pipeline definition ID}
    }
    "@
    
    $response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -ContentType application/json -body $JSON
    
    }
    

    In addition, we need set the Power Shell condition to Only when all previous tasks have succeeded, check the pic below.

    enter image description here

    And now, it will run the release test automation release pipeline after build release pipeline is completed & code is deployed to the environment