top of page

How to commit a Power Platform solution file to the source control (Git)(Part 3)

Updated: Mar 29, 2021

In the part 2 (https://www.dataobjectexception.com/post/how-to-distribute-solutions-from-one-power-platform-environment-to-another-part-2), I described the scenario 2 (to distribution a solution file from one environment to another).


Here, I intend to provide the procedure related to the scenario 2, "Commit the solution file in your source control" during the deployment from one environment (dev) to another (test).


Requirements


Please refer to the part 2 (How to distribute solutions from one Power Platform environment to another (Part 2)) to apply the same requirements.


Step 1 - Create and Manage the Apps in Azure Active Directory



Step 2 - Create the application user in your Power Platform environments



Step 3 - Create the project in your Azure Devops Organization



Step 4 - Handle the project settings - Service connections




1- Access the PAT functionality

2- Click on the "New Token" button

3- Fill the form



- Give a name.


- Select the expiration date.


- Keep custom defined.



- Make sure "Read & Execute" check box is checked.


- Once created, you'll receive an email mentioning that your PAT has been added to your Devops organization.





4- Copy the token and keep it safe

5- You can edit your PAT if you wish or regenerate simply your token.

Step 5 - Create your Azure Pipelines


We are going to create our deployment pipeline from dev environment to test environment.

Please refer to the part 2 (How to distribute solutions from one Power Platform environment to another (Part 2)) to apply the same step 5 : point 1 to 6. But, at the point 7, we need to edit the configuration related to the Agent Job.



Warning: We need to check "Allow scripts to access the OAuth token". It will retrieve the PAT (Personal Access Token) you just created. We'll use it to commit our solution in Git.





Once, you specify you agent pool, you need to specify your agent : I choose vs2017-win2016.

8- Add the tasks to your agent by clicking on the "+" button

9- Search the task regarding Power Platform. The lookup will display all tasks related to the solutions deployment.

10- Add the tasks we need to execute our scenario. Please, follow the sequence as below.

- Power Platform Tool installer is always the 1st step.

- Power Platform WhoAmI will help to test the connectivity.

- Power Platform Publish will publish the customizations.

- Power Platform Export will export the solution as unmanaged and/or as managed, from the environment.

- Power Platform Unpack will extract from the solution the last updates.

- Command Line Script will push the extracted solution in our source control.

- Power Platform Import will import the solution as unmanaged and/or as managed, in the environment.


11- For each task, configure the settings. we can rename all the tasks a we wish.


Please refer to the part 2 (How to distribute solutions from one Power Platform environment to another (Part 2)) to apply the same step 5 - the point 11.


Power Platform Unpack

We'll unpack the unmanaged solution before pushing the content in our source control.


- Fill the field "Solution Input File" with "$(Build.ArtifactStagingDirectory)\$(SolutionName).zip".

- Fill the field "Target Folder to Unpack Solution" with "$(Build.SourcesDirectory)\$(FolderRootDevTest)\$(FolderUnmanaged)\$(SolutionName)"

- Select the type of Solution : "Unmanaged".

- Make sure that "Allow overwrite of existing files" is checked.


Command Line Script

Fill the field with the following code :


echo commit all changes

git config user.email "firstname.lastname@domain.com"

git config user.name "Automatic Build"

git checkout --track origin/main

git add --all

git commit -m "solution init"

echo push code to new repo

git -c http.extraHeader="AUTHORIZATION: Basic $(System.AccessToken)" push origin main


Warning : Do not use AUTHORIZATION: Bearer. Microsoft mentions that we need to use AUTHORIZATION: Basic. Please, refer to the details : https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page


MY_PAT=yourPAT # replace "yourPAT" with your actual PAT

B64_PAT=$(printf "%s"":$MY_PAT" | base64)

git -c http.extraHeader="Authorization: Basic ${B64_PAT}" push origin main


Do the same with the managed solution, IF NEEDED.


12- We can extract the YAML of our agent job and validate the content of our tasks

13- Handle the variables related to the new scenario and the point 11. We have to add the following variables in our pipeline variables :

- System.AccessToken : the key generated in the step 4 (point 3). The script will retrieve the key using this variable.

- FolderManaged : the name we wish.

- FolderRootDevTest : the name we wish.

- FolderUnmanaged : the name we wish.


14- Handle the repositories permissions


14-1 Go the Project settings and select "Repositories"

14-2 Click on the "Permissions" tab. After, locate and select the user related to your azure Devops Organization.

Make sure that the "Contribute" security role is set to "Allow".


Step 6 - Run and Queue your Azure Pipeline



The job is complete.

Validation of the Unpack Task.

Validation of the Command Line Task.

Visualize the unpack solution in Git (source control). Please, go to Azure Repos and select the menu "Files".


bottom of page