Using fab deploy in Azure DevOps for Microsoft Fabric deployments

This post covers using fab deploy in Azure DevOps for Microsoft Fabric deployments based on YAML pipelines. In addition, this post shows how you can perform initial tests locally and introduces some AI concepts. Plus, this post shares plenty of links and advice.

You can find an example to accompany this post in the ‘create-genworkspace-fabric-cli.yml‘ file my ADO-fabric-cicd-sample Git repository. I also added some AI elements within this Git repository as well. Including the Fabric CLI skills that were announced during FabCon.

Fab deploy is a new Fabric CLI command that allows you to use the fabric-cicd Python library directly within Fabric CLI in order to deploy Microsoft Fabric items into Microsoft Fabric workspaces. Without the need to install the additional fabric-cicd library.

Typically this is done by deploying the metadata for items stored in a workspace that I configured with Microsoft Fabric Git integration. Like in the below flow.

Using fab deploy in Azure DevOps for Microsoft Fabric deployments
fab deploy flow

You can customize this flow how you see fit. For example, you can clone the sample Git repository locally and the issue the fab deploy command from your own machine. As shown in the following section.

Issuing fab deploy command locally

To issue the fab deploy command locally you first need to ensure the correct permissions are set in Microsoft Fabric to deploy to the target. Afterwards, make sure you install the latest version of the fabric CLI Python library with the below command.

pip install --upgrade ms-fabric-cli

Then authenticate with your account of choice. For local testing you can opt to enter ‘fab auth login’ and choose your authentication of choice. As per the below example.

PS C:\WINDOWS\System32> fab auth login
? How would you like to authenticate Fabric CLI? (Use arrow keys)
 > Interactive with a web browser
   Service principal authentication with secret
   Service principal authentication with certificate
   Service principal authentication with federated credential
   Managed identity authentication

Once authenticated you can start experimenting with the fab deploy command. I strongly recommend knowledge of both parametrization and configuration-based deployments within fabric-cicd to experiment with this command. My post that covers your first fabric-cicd deployment steps can help.

There are various parameters you can configure for the fab deploy command at runtime. However, providing a configuration file exists you can simply run the below.

fab deploy --config "./workspace/config.yml" --target_env "Test" -f

One key point to be aware of is that when testing interactively the specified environment must match exactly in your configuration file. Because it is also case sensitive.

Anyway, once done experimenting locally you can look to work with it in Azure DevOps.

Using fab deploy in Azure DevOps for Microsoft Fabric deployments

As you can see deploying with the fab deploy makes things so much easier. Due to the fact that it acts as a wrapper for the fabric-cicd Python library. In reality, you can manage the deployment with a slight variation of my previous Azure Devops scripts. Below are the essential steps required.

First, you need to specify the version of Python to work with via the Python version task.

- task: UsePythonVersion@0
  displayName: Use Python 3.12
  inputs:
    versionSpec: 3.12

Then install the Fabric CLI library. Note that you do not need to install the fabric-cicd library as well.

- task: PowerShell@2
  displayName: Install Fabric CLI
  inputs:
    targetType: inline
    pwsh: true
    script: |
      python -m pip install --upgrade pip
      pip install ms-fabric-cli

Then you need to authenticate. Which can be done with a service principal.

- task: PowerShell@2
  displayName: Authenticate with service principal
  inputs:
    targetType: inline
    pwsh: true
    script: |
      fab auth status
      fab auth login -u $(azure_client_id) -p $(azure_client_secret) --tenant $(azure_tenant_id)

Final part is to deploy to the new workspace with the fab deploy command.

- task: PowerShell@2
  displayName: Deploy workspace items with Fabric CLI
  inputs:
    targetType: inline
    pwsh: true
    script: |
      fab deploy --config "$(Build.SourcesDirectory)/workspace/config.yml" --target_env "$(TargetEnvironment)" -f

      if ($LASTEXITCODE -ne 0) {
        throw "Fabric CLI deploy failed for target environment: $(TargetEnvironment)"
      }

The example shown in my ‘create-genworkspace-fabric-cli.yml‘ file contains additional logic. Because I created it with additional AI elements. Including custom Copilot instructions and the Microsoft Learn MCP Server.

You can customize AI elements in the sample repository to suit your needs when working with GitHub Copilot in Visual Studio Code.

Advice for using fab deploy in Azure DevOps for Microsoft Fabric deployments

Below is some advice to help when working with the fab deploy command.

  • Be aware that environments specified in your configuration file are case sensitive.
  • When authenticating with a service principal ensure the correct permissions are configured in your fabric tenant settings. Plus, ensure that the account has the correct workspace access.
  • I recommend focusing on configuration-based deployments instead of adding the JSON-formatted parameters to keep your YAML pipeline as efficient as possible.
  • When looking to deploy with YAML Pipelines separate your different environments with stages.
  • You can setup Azure Pipeline environments to implement an approvals process.
  • For more complex YAML pipelines that require the fab deploy command consider working with GitHub Copilot in Visual Studio Code and the Microsoft Learn MCP Server. In order to implement more complex conditions and defensive logic.

Final words

I hope that by sharing knowledge about how to work with fab deploy in Azure DevOps for Microsoft Fabric deployments encourages others to look into it. Because it can help make your code more efficient and more readable to others.

At the same time, I do not want to take any of the attention away from the fabric-cicd Python library. Because it is still a fantastic Python library and you need some fabric-cicd knowledge for the fab deploy command to work effectively.

2 thoughts on “Using fab deploy in Azure DevOps for Microsoft Fabric deployments”

Leave a Comment