azure-devopsmicrosoft-fabric

MS Fabric project Deployment using Azure Pipelines


I am trying to deploy and setup Continuous Deployment for MS Fabric project using API's , Currently I am only considering a hello world type files, sample .pbix file and some other report for deployment. My current use case is simple, to make a small change in pbi or any other file and that same should trigger deployment into MS fabric workspace. Which API should I use? and what authenticaion mechanism I should use? Will I need app ID, tenant ID, workspace ID, app secret ? And what else will I need ? I am setting up deployment from local system first.


Solution

  • Per your expectation to import a .pibx report into your Microsoft Fabric workspace, I tested to use New-PowerBIReport locally and in Azure Pipelines. Here are the brief steps for your reference.

    1. As introduced in this document, create a service principal (app registration in my example: App-MicrosoftFabric) with the Contributor access to my DevWorkspace;

      Image

    2. Navigate to Admin portal -> Enable Service principals can use Fabric APIs;

      Image

    3. Generate client secret for the service principal and collect the tenantId, clientId & clientSecret;

    4. Install Microsoft Power BI Cmdlets;

      Install-Module -Name MicrosoftPowerBIMgmt -Force -AllowClobber
      
    5. Test the script locally to import the .pbix file and create a new report in the target workspace;

      # App-MicrosoftFabric
      $tenantId = "20247162-xxxx-xxxx-xxxx-8ee25c8bdd23"
      $clientId = "8a40233c-xxxx-xxxx-xxxx-4e577d178b23"
      $clientSecret = "xxxxxx"
      
      # Create secure client secret
      $secureClientSecret = ConvertTo-SecureString $clientSecret -AsPlainText -Force
      $credential = New-Object System.Management.Automation.PSCredential($clientId, $secureClientSecret)
      
      # Authenticate to Power BI service using the service principal
      Connect-PowerBIServiceAccount -ServicePrincipal -TenantId $tenantId -Credential $credential
      
      # Returns a list of Power BI workspaces
      Get-PowerBIWorkspace -Name 'DevWorkspace'
      
      # Returns a list of Power BI reports
      Get-PowerBIReport -Workspace ( Get-PowerBIWorkspace -Name 'DevWorkspace' )
      
      # Import PBIX file into the Power BI workspace
      New-PowerBIReport -Path '.\Tasks - Work.pbix' -Name 'WorkReport' -ConflictAction 'Overwrite' -Workspace ( Get-PowerBIWorkspace -Name 'DevWorkspace' )
      
      Disconnect-PowerBIServiceAccount
      
    6. Create sample YAML pipeline running on windows-lastest agents and define pipeline variables $(tenantId), $(clientId) and $(clientSecret) for the script to consume;

      trigger:
      - dev
      
      pool:
        vmImage: windows-latest
      
      steps:
      - powershell: |
          # Install MicrosoftPowerBIMgmt module
          Install-Module -Name MicrosoftPowerBIMgmt -Force -AllowClobber
      
          # Define script variables with the values of pipeline variables
          $tenantId = "$(tenantId)"
          $clientId = "$(clientId)"
          $clientSecret = "$(clientSecret)"
      
          # Create secure client secret
          $secureClientSecret = ConvertTo-SecureString $clientSecret -AsPlainText -Force
          $credential = New-Object System.Management.Automation.PSCredential($clientId, $secureClientSecret)
      
          # Authenticate to Power BI service using the service principal
          Connect-PowerBIServiceAccount -ServicePrincipal -TenantId $tenantId -Credential $credential
      
          # Returns a list of Power BI workspaces
          Get-PowerBIWorkspace -Name 'DevWorkspace'
      
          # Returns a list of Power BI reports
          Get-PowerBIReport -Workspace ( Get-PowerBIWorkspace -Name 'DevWorkspace' )
      
          # Import PBIX file into the Power BI workspace
          New-PowerBIReport -Path '$(System.DefaultWorkingDirectory)\Reports\Tasks - Work.pbix' -Name 'WorkReport' -Workspace ( Get-PowerBIWorkspace -Name 'DevWorkspace' )
      
          Disconnect-PowerBIServiceAccount
      

    The sample pipeline uses a simple CI trigger. You may specify path filters to the .pbix files in your repo based on your needs.