Here at Definitive Logic we do a lot of Power Platform development, but one thing that has been challenging for us is properly maintaining version control on these low-code solutions.  From our perspective, whether it is C# code for an Azure solution or a PowerApps Form, it is code and the development, testing, and support of that code must follow the DevOps methodology.  For those new to DevOps, it is a set of practices for the automation and coordination of software development by developers and its deployment by IT Operations. Azure DevOps is a Software as a Service (SaaS) platform which supports DevOps operations within the Microsoft Azure environment.

Recently Microsoft released an updated extension for Azure DevOps called the Power Platform Build Tools.  Our team quickly dove into the documentation and came across some gaps when implementing a DevOps pipeline.  Consequently, since we value information shared within the Microsoft community, we’d like to share some instructions for how to export and store a Power Platform solution using Azure’s DevOps Repository and the Pipelines feature.

These instructions assume that you have already configured an Azure DevOps Organization, as well as a Project. For more information on those steps:

Instructions

  1. From the Azure Portal, browse to All services, search for DevOps and select Azure DevOps.
  2. Select the relevant Project
  3. Select Pipelines
  4. In the top right corner, select New Pipeline
  5. Select Use the classic editor to create a pipeline without YAML.

6. Select the proper repository and branch, then select Continue
7. Under Select a template, select Empty job
8. Enter a descriptive name for your Pipeline.

9. Under Agent job 1, select the + to open the Add tasks
10. Select tasks Power Platform Tool Installer, Export Solution, and Unpack Solution
11. Next, under Agent job 1 select the Power Platform Export Solution task to configure the required fields. The Display Name filed will be auto-populated.
12. Set authentication type to service principal/client secret and then add a new service connection. The Server URL will be created as part of this task.

13. To get the Server URL, navigate to https://admin.powerplatform.microsoft.com/environments and select the environment you will be exporting from. Copy and paste the Environment URL. This will be the value of the Server URL.
14. To complete the creation of the App Service Principal, you will need to enter the appropriate Tenant ID, Application ID, and the Client secret for the Application ID. Instructions to do this can be found here: Create a service principal that uses a client secret credential
15. Assign a meaningful name to the connection and select Save.
16. To continue the configuration of the Export Solution task, enter a value for Solution Name. This is the name of the solution you will be exporting.

17. For the Solution Output File, add the path and .zip file name (ex: $(Build.ArtifactStagingDirectory)\(FileName).zip). This completes the configuration of the Export Solution task.
18. Select task Power Platform UnPack Solution. The Display Name will be auto populated.

19. For Solution Input File, enter the output file value which was used for the Export Solution task (ex: $(Build.ArtifactStagingDirectory)\(FileName).zip)
20. For the target folder, enter the final folder location (ex $(Build.SourcesDirectory)\(FileName)) At this point, a dropdown displaying Save & Queue will be accessible. Select Save from this dropdown to save the task configurations.
21. Next, go to “Add tasks” and select “Command line” to add this task to “Agent Job 1”
22. Paste the following into the script field for this task. You will need to substitute your values for {Domain}, {Project} and {Repository}, and replace {PAT} with a Personal Access Token (for guidance on how to generate a new token, refer to this article: Use personal access tokens):

23. Again, go to the Save & Queue dropdown and select Save.
24. Next, open a new browser tab, navigate to https://portal.azure.com and select App registrations.

25. Select your application, then navigate to API permissions.
26. Ensure that Dynamics CRM – user_impersonation is included by selecting Add a permission -> Dynamics CRM, checking user_impersonation, then selecting Add permissions.

27. Next, navigate back to https://admin.powerplatform.microsoft.com/environments and select your environment.

28. Select Settings->Users+permissions->Users
29. Select Manage users in Dynamics 365
30. In the dropdown, select Application Users

31. In the navigation bar, select New. In the dropdown, select Application User and fill out the required fields. Enter the Application ID that you used in the service connection earlier.

32. Select Save. The Application ID URI and Azure AD Object ID should auto populate.
33. Save and close this window.
34. In the Application Users view, select the new user then Manage Roles and ensure they have System Administrator.

All done! Your pipeline will now export your solution and commit the source code into a repository. You can now store Flows, PowerApps, and much more in a controlled repository and use this to automate deployment into production in a safe manner.

For more information on Pipelines, see Key concepts for new Azure Pipelines users.