Automated Solution Export and Backup Pipeline

Introduction

In today's fast-paced business world, companies use the Power Platform to make custom solutions, automate tasks, and make business processes smoother. As these solutions get more complicated, it's really important to have a strong backup plan. This article talks about why automatically exporting and backing up Power Platform solutions is crucial, and it gives you a simple guide on how to do it step by step.

Use Cases

  • Avoiding Mistakes: To prevent accidental deletions or errors as things become more complicated, it's crucial to keep a safe copy of your work. Safeguard your important settings and customizations from mistakes that may occur during updates.
  • Following Rules and Checks: Adhere to necessary rules and checks by regularly saving and storing your solutions for audits. Maintain a record of all changes made to your solutions for reference and understanding of what happened.
  • Teamwork Made Easy: Simplify collaboration among different teams by always having a dependable backup of solutions. Facilitate the sharing and movement of solutions to different locations effortlessly.
  • Getting Back on Track: Swiftly recover from setbacks by consistently having an up-to-date backup of Power Platform solutions. Quickly restore normalcy and minimize downtime with a robust backup plan.

Make sure your Azure DevOps Pipeline is set up and ready.

Step 1. Install Power Platform Build Tools and create a service connection. Follow this article for step by step process: Working with Service Connections in Azure DevOps (c-sharpcorner.com)

Step 2. Go to Azure Pipelines -> Create a new Starter Pipeline and update it as given below.

First of all, define the schedule to run the pipeline daily at 12 AM IST.

# Define scheduled triggers for the pipeline
schedules:
- cron: "30 18 * * *"
  displayName: DailyTriggerIST
  branches:
    include:
    - main

Step 3. Define variable group to store solution name to be exported.

# Define variables, in this case, a variable group for development
variables:
- group: dev-variable-group

Step 4. Create a new Variable Group. Go to library -> Create New Variable Group -> Give a name -> Define variables and save as shown below.

 Variable Group

Note. In the variable group's pipeline permissions add your YAML pipeline explicitly for variable group access.

Step 5. Now mention the agent and pool where your pipeline should run.

# Specify the agent pool and VM image to be used in the pipeline
pool:
  vmImage: windows-latest

Step 6. Now define the job name and pool for the current set of tasks. If the pool is not explicitly defined, it is inherited from the pipeline pool.

# Define the jobs to be executed in the pipeline
jobs:
- job: Solution_Backup_DEV
  displayName: Solution_Backup_DEV
  pool:
    vmImage: windows-latest

Step 7. Now define the steps for the current job. Add the first task "Power Platform Tool Installer" to install dependencies related to Power Platform tasks.

  # Define steps/tasks to be executed in the job
  steps:

    # Task to install Power Platform tools
  - task: PowerPlatformToolInstaller@2
    inputs:
      DefaultVersion: true
    displayName: 'Power Platform Tool Installer '

Step 8. Now add solution export in the managed mode task.

    # Task to export a managed Power Platform solution
  - task: PowerPlatformExportSolution@2
    inputs:
      authenticationType: 'PowerPlatformSPN'
      PowerPlatformSPN: 'DEV'
      SolutionName: '$(SolutionDemo)'
      SolutionOutputFile: '$(Build.ArtifactStagingDirectory)/Solutions/Managed/$(SolutionDemo)_managed.zip'
      Managed: true
      AsyncOperation: true
      MaxAsyncWaitTime: '60'
    displayName: 'Power Platform SolutionDemo Export Managed '

Step 9. Now add solution export in unmanaged mode task.

    # Task to export an unmanaged Power Platform solution
  - task: PowerPlatformExportSolution@2
    inputs:
      authenticationType: 'PowerPlatformSPN'
      PowerPlatformSPN: 'DEV'
      SolutionName: '$(SolutionDemo)'
      SolutionOutputFile: '$(Build.ArtifactStagingDirectory)/Solutions/UnManaged/$(SolutionDemo).zip'
      AsyncOperation: true
      MaxAsyncWaitTime: '60'
    displayName: 'Power Platform SolutionDemo Export UnManaged '

Step 10. Now add a task to unpack solution contents.

    # Task to unpack the unmanaged Power Platform solution
  - task: PowerPlatformUnpackSolution@2
    displayName: 'Power Platform SolutionDemo Unpack '
    inputs:
      SolutionInputFile: '$(Build.ArtifactStagingDirectory)/Solutions/UnManaged/$(SolutionDemo).zip'
      SolutionTargetFolder: '$(Build.ArtifactStagingDirectory)/Solutions/UnPack'

Step 11. Now add a "copy files task" to copy all contents from the Artifacts folder to the Source Directory.

    # Task to copy files from the artifact staging directory to the source directory
  - task: CopyFiles@2
    displayName: 'Copy Files to repos'
    inputs:
      SourceFolder: '$(Build.ArtifactStagingDirectory)'
      Contents: '**'
      TargetFolder: '$(Build.SourcesDirectory)'
      OverWrite: true

Step 12. Now add a command line script task to check in files in the source branch.

    # Task to run command line scripts (Git commands)
  - task: CmdLine@2
    displayName: Command Line Script
    inputs:
      script: |
        git config user.email "Your Email ID"
        git config user.name "Saksham Gupta"
        git checkout -b main
        git pull
        git add --all
        git commit -m "Solution Backup"
        echo push code to new repo
        git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push origin main -f
    env:
     MY_ACCESS_TOKEN: $(System.AccessToken)

Note. Make sure that the build service account has 'contribute' access set to allow. To verify go to Main(Source Branch)-> Branch Security-> Build Service User as shown below.

Contribute

Step 13. Now add the publish build artifact task. This artifact can be used for deployments in higher environments.

    # Task to publish build artifacts
  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: drop'

Step 14. Verify files are updated in repos. Below is a sample folder structure for the above implementation.

 Folder structure

The below screenshot is from a successful scheduled run for the YAML pipeline.

 YAML pipeline

Note. I have attached the complete YAML code along with this article for reference.

Conclusion

Automatic backup and export of Power Platform solutions are crucial for keeping them stable. If organizations use this easy step-by-step guide, they can reduce risks, make sure they follow the rules, and work together more smoothly. Azure DevOps Pipeline not only automates the backup but also creates a history with versions. This helps in quickly fixing issues and managing Power Platform solutions effectively.

Being proactive about exporting and backing up solutions is important for organizations using the Power Platform. With a well-organized system, teams can confidently handle challenges, work better together, and ensure the Power Platform solutions stay stable for a long time. Please feel free to reach out in case of any concerns.


Similar Articles