Build Azure DevOps Pipelines for Dynamics 365 CRM/Power Platform- Part 2
Build Pipeline: Export solution from development environment to Repository
We can build this azure pipeline to export solution from dev environment and unpack the solution and store it at our repository and deploy the same solution to destination environment so that this can be a single-source of truth for developers.
You can create two pipelines one as managed solution for deployment purpose and other one as unmanaged solutions to keep as backup.
Follow below link to setup Azure DevOps, Power Platform Installation and Service Connection setup.
Create a pipeline
In Azure DevOps, click on the Pipelines link on the left side and create your Pipeline and chose Classic editor.
To create pipeline for the Power Apps Build tasks, we will use the classic editor.
Default Azure Repos Git
We will use Azure Repos Git (which is default) for our repository. Click continue.
Empty Jobs
We will build our pipeline using an Empty job.
Give your pipeline a name, Save your pipeline by choosing the “Save & queue” and then “Save”.
Allow scripts to access the OAuth token
Select the Agent job, scroll down on the properties and check the “Allow scripts to access the OAuth token”.
Add Task
On the “Agent job 1” section, click the “+” button to add a new task.
Power Platform Tools Installer Task
On the left of the screen, search for “PowerApps tools” and add the PowerApps Tool Installer.
This task installs a set of Power Platform–specific tools required by the agent to run the Power Platform build tasks. This task doesn’t require any additional configuration.
Power Platform Export Solution task
Now add the PowerApps Export Solution task, this task exports solutions from the CRM environment.
In this step will export the solution to a folder on the temporary virtual machine.
Add Service Connection
Connection to your CRM instance from where you need to export the solution(please refer part- 1 where we have configured service connection)
Solution name
Solution name is the variable name, please refer- Set variable section.
$(SolutionName)
Solution Output File
Unmanaged/Managed Solution:
$(Build.ArtifactStagingDirectory)\$(SolutionName).zip
The solution name is a variable, we will setup it in a few steps below.
$(Build.ArtifactStagingDirectory)\$(SolutionName)_managed.zip
Power Platform Unpack Solution Step
After exporting the solution from our source sandbox environment, which is a zip file, before adding to source control we need to unpack it and then we will be Pushing it to source control so that we can easily see the configuration files in our repository.
Add a new task and find PowerApps Unpack Solution.
This will unpack the solution that we exported in the previous step and it requires some additional settings:
Solution Input File
Unmanaged solution:
$(Build.ArtifactStagingDirectory)\$(SolutionName).zip
Target Folder to unpack solution
Unmanaged solution:
$(Build.SourcesDirectory)\$(SolutionName)
Type of Solution
Select as Unmanaged or managed:
Pushing Unpacked Solution to Source Control Repository
Now we need to add the Command Line Script task to our pipeline to push the unpack solution files to source control.
Add a new task, search for Command line and add it to the pipeline.
Add Git Commands
We will need to add the script that will run the Git commands to add, commit, push the unpack solution to source control. (replace username@x.onmicrosoft.com)
echo commit all changes
git config user.email “username@x.onmicrosoft.com”
git config user.name “Automatic Build”
git checkout master
git add — all
git commit -m “solution export”
echo push code to new repo
git -c http.extraheader=”AUTHORIZATION: bearer $(System.AccessToken)” push origin master
Set Variables
We need to define our $solution variable that used in our Export and Unpack solution steps earlier.
Choose “Variables” tab in the pipeline editor, and then “+Add”
Run Pipeline
Job Running
Click on the Agent job to view progress. After a few minutes, the pipeline should be complete, and the solution should be in the source repo.
Solution files in source control
Navigate to Repos and you should see your unpacked solution files. Each time your run this pipeline, you should be able to see your changes to your configuration in the various files.
Follow below link to import solution to Production/test environment: