0
votes

Im working with a project in Azure DevOps. The project is spread out in multiple repositories containing Azure functions, logic apps etc with multiple CI/CD Pipelines. Currently I'm working on an end-to-end testsolution for this project.

I would like to have the tests in a seperate repository and be able to trigger the tests when other CD-pipelines run. How can I accomplish this? The tests are built with MSTest and are currently run in a build-pipeline.

1
Hi Did you get a chance to try out below solution? Free to let me know if there is any question. - Levi Lu-MSFT

1 Answers

0
votes

You can use rest api to trigger the tests when other CD-pipelines run.

If you want to run the tests in a separate CI pipeline. You need to create a CI pipeline to run the tests for this test repository. Then add a script task in the CD pipeline to call build queue restful api. Please check below script example in powershell task.

$url = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds?api-version=5.1"

$qbody = '{ 
                "definition": {
                   "id": "the definition id of the test CI pipeline"    
                  } 
              }'

$update = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} -ContentType "application/json"  -Method post -Body $qbody

You aslo need to go to the agent job and check Allow scripts to access the OAuth token. enter image description here

Another way to trigger the test CI pipeline from CD pipeline is to add Trigger Azure DevOps Pipeline task in CD pipeline and configure it to trigger the test CI pipeline.