In this blog post we will cover exporting the solutions so that we can commit them to source control and also ensure that we will have the right solution to deploy to our upstream environments later. I always configure both the managed and unmanaged solution export (it takes a little longer up front) as it provides the cleanest way (in my experience) to deploy a valid managed solution to the upstream environments.
Creating the pipeline
Again we're going to focus on the pipeline itself rather than installing the extension to manage this, so once you log in to Azure DevOps:
- In the left navigation of DevOps, click on Pipelines
- Then click on the New pipeline button in the top right
- Select Use the classic editor
- Select the Repository
- Select the Team Project (the current project)
- Select the repository (PP_Solutions)
- Select the main branch
- click Continue
- Select a template
- select the Empty job option link at the top of the list of types.
Configuring the pipeline
- Name: I usually name them in a manner that lets me follow the order easily such as: 02 - Export Solutions, or PP-02 - Export Solutions
- Agent Pool can be left as default for now
- Agent Specification: leave as default or select Windows-Latest so you don't have to keep updating it.
- Next, click on the item called Agent job 1, change the name to Export Solutions (you can update the name if you want, I would recommend setting a name if you are going to have additional jobs in a single pipeline).
- Then in the additional options, check the Allow scripts to access the OAuth Token checkbox.
Adding the build pipeline tasks
- Click the + icon
- In the search box type Power Platform Tool Installer
- Click Add next to the task that's displayed under the search box
- again in the search box type Power Platform Export Solution
- Click Add next to the task twice (once for the unmanaged and once for the managed solution) that's displayed under the search box.
- Next in the search box type Power Platform Unpack Solution
- Click Add next to the task
- Next in the search box type Command Line Script
- Click Add next to the task
- Finally, in the search box type Publish Pipeline Artifact
- Click Add next to the task
- Your agent job should now look like this:
Agent job after adding tasks
Configuring the pipeline tasks
As usual, we can skip configuring the Power Platform Tool Installer task, it just needs to be present.
- Click on the first Power Platform Export Solution task and rename it to Power Platform Export Unmanaged Solution
- On the details tab of the task set the following
- Service Connection - use the service connection set up in the previous blog post
- Solution Name - use the internal name of the solution
- Solution Output File - $(Build.ArtifactStagingDirectory)\{SolutionName}_unmanaged.zip where {SolutionName} is the name from the previous step.
- Leave all the other settings as default
- Next, click on the first Power Platform Export Solution task and rename it to Power Platform Export Managed Solution
- On the details tab of the task set the following
- Service Connection - use the service connection set up in the previous blog post
- Solution Name - use the internal name of the solution
- Solution Output File - $(Build.ArtifactStagingDirectory)\{SolutionName}_managed.zip where {SolutionName} is the name from the previous step.
- Check the Export as Managed Solution checkbox.
- Leave all the other settings as default
- Unpack the solution so that we can commit the source to the Git repository
- Select the Power Platform Unpack Solution task
- Set the Solution Input File value to the same as Solution Output File in the Power Platform Export Unmanaged Solution task
- Set the target folder $(Build.SourcesDirectory)\{SolutionName} where {SolutionName} is the name used in the previous steps
- Set the Type of Solution to Unmanaged
- Commit the extracted solution to Git
- Select the Command Line Script task
- In the Script text box enter the following script
echo commit all changesgit config user.email "your.email@domain.com"git config user.name "Automatic Build"git checkout maingit add --allgit commit -m "solution init"echo push code to new repogit -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push -f origin main
- Publish the artifact.