We’re ready to setup our new build pipeline in Azure DevOps. This pipeline will consist of three steps: create a new VM, run all the build steps, and delete the VM:
First of all check that your pipeline runs on Azure pipelines (aka Azure-hosted):
The create and delete steps will run on the Azure Pipelines pool. The build step will run on our DevTestLabs pool, or the name you gave it when configuring the artifact on DevTest Labs or the script on the VM.
Create Azure DevTest Labs VM #
Create a new pipeline and choose the “Use the classic editor” option. Make sure you’ve selected TFVC as your source and click “Continue” and “Empty job”. Add a new task to the pipeline, look for “Azure DevTest Labs Create VM”. We just need to fill in the missing parameters with our subscription, lab, etc.
Remember this step must run on the Azure-hosted pipeline.
Build #
This is an easy one. Just export a working pipeline and import it. And this step needs to run on your self-hosted pool:
Optional: use SelectiveSync (not recommended, see next option) #
You can replace the Database Sync task for a PowerShell script that will only sync the tables in your models:
Thanks Joris for the tip!
Optional: use d365fo.tools to sync your packages/models #
This is a better option than the SelectiveSync above. You can synchronize your packages or models only to gain some time. This cmdlet uses sync.exe like Visual Studio does and should be better than SelectiveSync.
Add a new PowerShell task, select Inline Script and this is the command:
Invoke-D365DbSyncModule -Module "Module1", "Module2" -ShowOriginalProgress -Verbose
Optional: use d365fo.tools to deploy SSRS reports #
If you really want to add the report deployment step to your pipeline you can save some more extra time using d365fo.tools and just deploy the reports in your models like we’ve done with the DB sync.
Run this in a new PowerShell task to do it:
Publish-D365SsrsReport -Module YOUR_MODULE -ReportName *
Delete Azure DevTest Labs VM #
It’s almost the same as the create step, complete the subscription, lab and VM fields and done:
And this step, like the create one, will run on the Azure-hosted agent.
Dependencies and conditions #
When all three steps are configured we need to add dependencies and conditions to some of them. For example, to make sure that the delete VM step runs when the build step fails, but it doesn’t when the create VM step fails.
Build #
The build step depends on the create VM step, and will only run if the previous step succeeds:
Delete VM #
The delete step depends on all previous steps and must run when the create VM step succeeds. If the create step fails there’s no VM and we don’t need to delete it:
This is the custom condition we’ll use:
and(always(), eq(dependencies.Job_1.status, 'Succeeded'))
If you need to know your first step’s job name just export the pipeline to YAML and you’ll find it there:
If this step fails when the pipeline is run, wait to delete the VM manually, first change the VM name in the delete step, save your pipeline and then use the dropdown to show the VMs in the selected subscription, and save the pipeline.