Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications

| | | | |

Portal Support for Power Platform CLI

Post Author: Joe D365 |

As part of Release Wave 2, Microsoft is updating the Power Platform CLI by expanding on administrative commands that can be made against Power Apps Portals. That’s right – the ability to authenticate to Dataverse, list available Portal websites, and upload or download Portal configuration files are now available via Command Line Interface. This means Professional Developers can benefit from faster, more reliable Portal deployments that enable Continuous Integration/Continuous Deployments (CI/CD), not only by integrating to Source Control, but also allowing deployments to any Dev/Test/Production Dataverse environment. Today’s blog will highlight the new features included in Portal Support for Power Platform CLI and will explore the possibilities for automation via Azure DevOps Pipelines.

Graphical user interface, text

Description automatically generated

Power Platform CLI brings automation and scripting benefits to Dataverse

So, what is the Power Platform CLI? Microsoft defines it as:

"Microsoft Power Platform CLI is a simple, one-stop developer CLI that empowers developers and ISVs to perform various operations in Microsoft Power Platform related to environment lifecycle, authentication, and work with Microsoft Dataverse environments, solution packages, portals, code components, and so on."

What does this really mean to Pro-Dev App Makers? Look at the features and benefits the CLI provides:

  • Ability to create solution files that are compatible with Dataverse
  • Authenticate and Publish changes to Dataverse
  • Install and Use CLI via Azure DevOps Pipelines to introduce automation to deployment processes
  • Scripting vs. Navigating – scripting your commands is faster and more efficient than navigating through the application (and opening various windows along the way)
  • Shared sense of accomplishment when a script runs successfully

Portal Support Benefits

How do these benefits apply to Power Apps Portals? With Power Platform CLI now supporting Portals, Developers can easily download Portal website configuration files to take advantage of:

  • Local Development Experience
    • Use the Power Platform Tools extension for Visual Studio Code to make local changes to Portal code
  • Source Control Integration
    • Use those portal configuration files to maintain source control
  • Continuous Integration/Continuous Deployment (CI/CD)
    • Facilitate deployments with automation and scheduling by installing the Power Platform CLI on Azure DevOps Pipelines

Get Started

Let’s explore the possibilities of Portal Support for Power Platform CLI through these four main steps:

  1. Install Latest CLI
  2. Build Pipelines in Azure DevOps
  3. Portal Development Experience
  4. Release Pipeline in Azure DevOps

Scenario

Imagine a fictional organization (simply called Cookie Company) that is working with Developers to create and support their Portal website. As a cookie baking and delivery organization, Cookie Company uses Power Apps Portals and Microsoft Dataverse to operate their business online.

Graphical user interface, text

Description automatically generated

Assumptions

Let’s make the following assumptions about Cookie Company and their Dataverse environments:

  • Cookie Company has a tenant with Dev and Test environments
  • Each environment has Dataverse and Customer Self Service Portal installed
  • App Registration created in Azure Active Directory with appropriate permissions granted
  • App User created in Dev and Test environments and assigned appropriate Security Roles
  • Cookie Company has an Azure DevOps organization and project with Azure Git Repos

Install Latest CLI

To get started on this journey with Cookie Company, Developers should first install the latest version of Power Platform CLI on the machines where they will perform local development using Visual Studio Code. This can be done by navigating to View > Extensions in Visual Studio Code. Search for Power Platform Tools and install the extension.

Graphical user interface, text, website

Description automatically generated

Build Pipeline: Portal To Source Control

Next, let’s navigate to Azure DevOps to create our Build Pipelines. Let’s start with Portal To Source Control.

Create a new Pipeline in Azure DevOps. Use a new Starter Pipeline to generate a YAML template that can be easily modified to define the following pipeline tasks:

1. PowerShell Task

Used for installing the Power Platform CLI on the Agent VM.

A picture containing text

Description automatically generated

2. PowerShell Task

Used for authenticating to Dataverse and Downloading Portal website configuration files via CLI

Graphical user interface

Description automatically generated with low confidence

3. Command Line Task

Standard commands for commit and push Portal website configuration files to Git repository

4. Publish Pipeline Artifacts

Publishes artifact of latest Portal website configuration files for use in Release Pipeline

While editing the Pipeline, define the following variables using your App Registration from Azure Active Directory:

  • PowerPlatformInstanceURL
    • The Organization URL for this environment
  • AADDirectoryId
    • Directory ID for the App Registration in Azure Active Directory
  • AADApplicationId
    • Application (Client) ID for the App Registration in Azure Active Directory
  • AADApplicationSecret
    • Application Secret for the App Registration in Azure Active Directory
  • PortalId
    • The unique identifier for your portal website
      • This can be found using CLI input pac paportal list
  • AuthProfileName
    • Power Platform CLI uses an authentication profile. This can be any name, such as “Development”.

Be sure to save your changes, then continue building the next pipeline.

Build Pipeline: Source Control to Portal

The Source Control to Portal Build Pipeline is built following similar steps to the previous Build Pipeline, however the big difference is that this time instead of Downloading Portal configuration files, we will be uploading to Dataverse.

Create another Pipeline in Azure DevOps using the Starter Pipeline template. Define your variables like before, but this time, define the following tasks:

1. PowerShell Task

Used for installing the Power Platform CLI on the Agent VM (same as previous pipeline)

2. PowerShell Task

Used for authenticating to Dataverse and Uploading Portal website configuration files via CLI

Graphical user interface, text, application

Description automatically generated

Be sure to save the changes to Source Control to Portal pipeline.

We do have to provide the Build Service the necessary permissions in Azure DevOps to interact with our Repository from Pipelines.

Graphical user interface, text, application

Description automatically generated

With the Build Service permissions in place, run the first Build Pipeline – Portal To Source Control. This will download the Portal website configuration and do an initial push to the Git repository. In our testing, this pipeline takes under 2 minutes to execute. With a successful pipeline execution and the Portal website configuration files now in Source Control, we can continue with Portal Development.

Portal Development

Developers can now clone the Git repository in Azure DevOps using Visual Studio Code. This will make a copy of the Portal Configuration files from the Git repository on the developer’s local machine. Developers can open this folder using Visual Studio Code to see the Portal Configuration file structure.

Text, application

Description automatically generated

Developers can make necessary changes to any of the following via Visual Studio Code:

  • HTML, JavaScript, CSS in Web Pages
  • Content Snippets
  • Images and other Web Files (JS, CSS libraries)

Text

Description automatically generated

Once these customizations are saved locally, Developers can use the Source Control integration within Visual Studio Code to commit and push all changes back to the Git repository.

After the successful commit and push, run the Source Control to Portal pipeline. This will upload the changes included in the latest commit back to the Portal in the Dev environment, where Developers will need to Sync Configuration in the Power Apps Portal Editor (or clear the Portal website cache) to begin their validation and unit testing of the Portal website.

After validation has taken place in Dev, we are ready to deploy to the Test environment. Run the Portal to Source Control pipeline one final time to get the latest configuration from the Portal website and publish a release artifact.

Text

Description automatically generated

Release Pipeline

Now that our customizations and latest changes are published to an artifact in Azure DevOps, let’s use that artifact for creating a Release Pipeline called Deploy to Test.

Navigate to Azure DevOps and create a new Release Pipeline. Start with an empty job, then define the artifact we previously published when running the Portal to Source Control pipeline.

Graphical user interface

Description automatically generated with medium confidence

This release pipeline only needs 1 stage. Similar to our previous Pipelines, add the following tasks:

1. PowerShell Task

Used for installing the Power Platform CLI on the Agent VM

2. PowerShell Task

Used for authenticating to Dataverse and Uploading Portal website configuration files via CLI

Graphical user interface, application, email

Description automatically generated

Add environment variables to the task (much like we did in the Build Pipelines). Be sure to use the values for your target environment (Test or Prod). Save your changes and create a new Release in Azure DevOps to trigger the Deploy to Test release pipeline.

Graphical user interface, text, application

Description automatically generated

After successful execution, Developers will need to Sync Configuration (or clear Portal website cache) in the target environment to see the latest changes on the website. In our testing, we were able to successfully validate changes in a Test environment. You can also easily expand on this Release Pipeline to add additional targeted deployments, such as targeting the Production environment.

Limitations

Note that Portal Support for Power Platform CLI is on its initial release, and with that come some limitations. The following are limitations encountered in testing, or highlighted in Microsoft’s documentation:

  1. Supported Portal Tables
    • Most Portal tables in Dataverse (titled with adx_ prefix) are supported on the Portal commands in the Power Platform CLI.
    • Not Supported - Custom Tables, and those tables that are template specific (Forums, Ideas) are not supported.
  2. Maximum Path Length
    • Developers commonly encounter a Maximum Path Length error when working in Source Control repositories with many nested folders that push the path length passed its maximum threshold.
    • Our team encountered this error during the testing of this process. It is recommended to use short file and folder names to prevent encountering this error.
  3. Windows 10 Support
    • Microsoft highlights in their documentation that Power Platform CLI is only supported on Windows 10 devices.
    • The documentation for Visual Studio Code also mentions the Power Platform Extension is confirmed to work on Windows 10 and macOS devices.

Conclusion

Portal Support for Power Platform CLI makes Portal Development faster by providing a local development experience, and when partnered with Azure DevOps Pipelines, provides an avenue for implementing Continuous Integration. This quick demo did not go into all the possibilities with this approach – consider the possibilities with Branching strategies in source control or implementing schedules and triggers on Pipelines for automated execution (and less manual work!)

Have fun, and Happy Coding!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

Leave a Reply

Your email address will not be published.

PowerObjects Recommends