In this blog, we will see how to setup Azure DevOps pipeline to deploy Power App Solutions in different environments.
We all know that a good application lifecycle strategy is necessary for any organization, as it helps address common challenges like maintaining consistency, reducing manual effort, minimizing build errors, and lowering risks during deployment.
By integrating Power Platform with Azure DevOps, teams can simplify and automate key tasks like exporting, importing, and updating apps or flows. This ensures that releases are faster, more consistent, and that version control and testing are managed effectively. Let’s dive into how this integration can streamline your development and deployment process. There are some prerequisites as given below.
- Power Apps Service Connection (refer https://asifwaquar.com/power-platform-service-principal-setup-for-azure-devops/)
- Power Apps build extension in Azure DevOps. (https://marketplace.visualstudio.com/items?itemName=microsoft-IsvExpTools.PowerPlatform-BuildTools)
Step 1: If you don’t yet have a Power Apps account, please signing up for a Power Apps trial account to get started.
https://www.microsoft.com/en-sg/power-platform/products/power-apps/
Step 2: Go to power platform admin account https://admin.powerplatform.microsoft.com/ and choose environment group tab. Now create a new environment group by clicking on New Group button and providing the details.
Environment groups are designed to help administrators organize their flat list of environments into structured groups based on different criteria.
Step 3: Let’s create separate environments (Development, QA, and Production) to effectively deploy and manage your Power Apps solutions, ensuring a smooth and organized development and deployment process.
- Go to the environments tab.
- Click on the new button
- Fill the details of environment such as name, environment group (created in step 2), location, , environment type.
- Database (Dataverse)
Step 4: Now our Dev,QA environments are ready.
Step 5 : Install the Power Apps Build tools for Azure DevOps.
- Go to the visual studio market place. (https://marketplace.visualstudio.com/search?term=Power%20Apps&target=AzureDevOps&category=All%20categories&sortBy=Relevance)
- Click on Azure Devops Tab.
- Search for power apps tool
Step 6 : Click on Get it free button and choose the organisation to install.
Choose organisation to install
Step 7 : Install some other useful extensions such as Replace Token.
Step 8 : Create the service principal using power app connection.
Fill environment URL, Tenant ID, Application ID (App registration), Secret ID (Client Secret of App Registration).
Step 9 : Now, let’s provide azure devops project repository permissions.
- Go to project settings and repository tabs.
- Choose the project repository.
- Choose Project collection build service accounts and provide contribute permission
Step 10 : Do the same under users “Project name” build service account. provide contribute permission.
Step 11 : The next step is to add the service principal as a user in your Power Platform environment to ensure it has the necessary permissions to run the pipelines.
- Go the environments tab in admin power apps.
- Choose the environment name (Dev or QA).
- Choose users option.
Select app users list.
Click on the new app user
click on the add an app and choose the app registration which was created in azure.
After selecting app registration, choose the business unit.
Choose the application user and edit the security roles. Provide the role system administrator.
Choose system administrator role and make to repeat the same process for other environments (QA/PROD)
Step 12 : The next step will be to build the pipeline, but before doing so, we need to create a Power Apps solution. Let’s begin by creating a solution and linking all of your applications, connectors, and Power Automate flows within it. This will allow for seamless deployment across different environments.
Solutions are used to transport apps and components from one environment to another or to apply a set of customisations to new or existing apps.
To create power app solution go to the https://make.powerapps.com/ and choose solutions tab. Make sure to change the environment.
Step 13 : Click on the new solution button and provide the solution name, publisher and version.
The solution publisher indicates who developed the app. For this reason, you should create a solution publisher that is meaningful.
Create Publisher
Step 14 : Now let’s create the app and add to the existing solution to package it.
App is created.
Choose the solution to add the app.
Click on the add existing button and choose the type of app.
Choose the app name.
Now app is added to the solution.
Step 15: Let’s initialise the devops repository.
Step 16 : Now let’s create a devops pipeline to deploy this app solution to QA environment.
Choose classic editor.
Choose Azure Git Repo and click on the continue button. It will open choose template screen.
Choose the empty job template.
Step 17 : To create a pipeline with blank template, first choose agent job name.
First we want to export the power app solution. Therefore, I will give my agent job name to solution export.
Now click on the + icon of agent job tab to add a task. and search for power platform.
Step 18 : Choose the task power platform tool installer. You don’t need to change any setting here.
Step 19: Now you need to know which environment you are connecting. Choose another task Power Platform who am I . It will tell you which connection you are connecting.
Choose the service connection details.
Step 20: Now, we need to export our power platform solution. Search for Power Platform export solution task.
Step 21: Provide the details to export the solution such as Service Connection details, Solution Name.
Create a variable name SolutionName.
Pass the solution variable and provide the output file path. In my case, I have provided the output file path as given below
Solution Output File :
$(Build.StagingDirectory)\$(SolutionName)_Unmanaged.zip
Choose export solution as asynchronous operation checkbox.
Step 22 : Now we need to unpack the solution. Search for Power Platform unpack solution.
In this step Solution Input File will be same as Solution Output File of Solution Export task.
Solution Input File :
$(Build.StagingDirectory)\$(SolutionName)_Unmanaged.zip
Target Folder to Unpack Solution
$(Build.SourcesDirectory)\$(SolutionName)\Unmanaged
Step 23 : Now add a task publish build artefacts.
Update path to publish. It will be same path of previous step of Target Folder to Unpack Solution
$(Build.SourcesDirectory)\$(SolutionName)\Unmanaged
Step 24: Now add command line script task.
Step 25 : Provide the given below script in command line to execute. It will perform below operations.
- check out from main branch
- add all files to git repo
- commit changes of the solution
- Push all the files to the origin.
cd $(Build.SourcesDirectory)
# Set a per-project email address and username
git config user.email "[email protected]"
git config user.name "Asif Waquar"
# Navigate to the main branch
git checkout -B main
# Update the local version of a repository from a remote
git pull
# Add all files to the Git repository
git add --all
# Record the changes in the repository
git commit -m "Updated the solution"
# Authenticate against a git repository in a build process
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push origin main
Step 26: Save and run the pipeline.
Step 27 : Save the pipeline and queue to run it.
Click on the solution export job.
If you encounter the error shown below, it indicates that no free Azure DevOps agent is currently available to run your job. In this situation, you’ll need to set up a new agent to proceed or fill the below given form to get a free agent from Microsoft.
https://aka.ms/azpipelines-parallelism-request
Create a new agent pool to run the pipeline.
- Go to project settings
- Click on Agent Pool
- Create New Agent Pool
- Choose option from self hosted or VM Scale set.
- Provide subscription details if you are choosing VM Scale set and authorise it.
- Provide VM scale set details and Grant permission to run all pipelines.
Update the agent details to run the pipeline.
Step 28: Change the VM agent settings to scale down to 0. If it’s not in use.
Check if it agent jobs are online or running.
Go to Azure VM Scale set and choose operations tab. Make sure update is manual but to detect agents. Please change to automatic then revert back to manual
Now you can see VM agents are online.
Run the pipeline.
If you are encountering the issue mentioned above, it likely means that haven’t allowed to use oauth token if you solution export agent job. Please allow it and rerun the job.
After rerun our build pipeline is completed.