Edit

Share via


Tutorial: Use variable libraries to customize and share item configurations (preview)

This tutorial shows you how to use dynamic content in Microsoft Fabric data pipelines. When you create a variable library item and add variables to it, you can automate values for various stages of your deployment pipeline. In this tutorial, you copy data from one lakehouse to another. Then you use the variable library to set the source and destination values for the copy activity.

In this tutorial, you:

  • Create a variable library.
  • Add variables to the library.
  • Define additional value sets for the variables.
  • Consume the variables in another item in the workspace (a data pipeline).
  • Edit the variables in a Git repository.
  • Create a deployment pipeline and deploy the variable library.
  • Change the active value set in the target stage of the deployment pipeline.
  • Show that the value of the variable complies with the active value set in each stage.

The following diagram shows the workspace layout for this tutorial.

Diagram of a workspace layout.

Note

The Fabric variable library item is currently in preview.

Prerequisites

Create the Stage LHs workspace, SourceLH_Stage lakehouse with sample data, and Pipeline_Stage pipeline

First, create a workspace and lakehouse to use as your initial staging data:

  1. Go to Power BI.

  2. On the sidebar, select Workspace.

  3. Create a workspace. Call it Stage LHs.

    Screenshot of the button for creating a new workspace.

  4. Create a lakehouse:

    1. At the top of the workspace, select New item.

    2. Under Store data, select Lakehouse.

      Screenshot of the tile for selecting a lakehouse as a new item.

    3. Enter the name SourceLH_Stage, and then select Create.

  5. Create a pipeline:

    1. In the lakehouse, select New data pipeline.

      Screenshot of the tile for creating a new data pipeline.

    2. Enter the name Pipeline_Stage, and then select Create.

    3. In the Copy data into Lakehouse wizard, on the Choose data source page, select Sample data.

      Screenshot of the page for choosing a data source for copying data into a lakehouse.

    4. Select Public Holidays.

      Screenshot of selecting Public Holidays sample data.

    5. After the sample data finishes loading, select Next.

    6. On the Connect to data destination page, select Next.

      Screenshot of details for a pipeline destination.

    7. On the Review + save page, select Save + Run.

      Screenshot of the page for saving and running a pipeline.

Create the Source LHs with Variables workspace

Now, create the workspace that you'll work out of and use with your variable library:

  1. Go to Power BI.

  2. On the sidebar, select Workspace.

  3. Create a workspace. Call it Source LHs with Variables.

Create the SourceLH_Dev, SourceLH_Test, and SourceLH_Prod lakehouses

Next, create the three lakehouses to use with the variable library:

  1. Create the first lakehouse:

    1. On the sidebar, select the Source LHs with Variables workspace.

    2. Select New item.

    3. Under Store data, select Lakehouse.

    4. Enter the name SourceLH_Dev, and then select Create.

  2. Create the second lakehouse by following the preceding steps. Name it SourceLH_Test.

  3. Create the third lakehouse by following the preceding steps. Name it SourceLH_Prod.

  4. On the sidebar, select the Source LHs with Variables workspace and make sure that it contains all the newly created lakehouses.

Get the workspace IDs and object IDs for lakehouses

In these steps, you get the unique identifiers to use in your variable library:

  1. In Power BI, on the sidebar, select the Stage LHs workspace.

  2. In the workspace, select the SourceLH_Stage lakehouse.

  3. Copy the workspace ID and the lakehouse object ID in the URL.

    Screenshot that shows how to get the workspace identifier and the lakehouse object identifier.

  4. Repeat the preceding steps for the SourceLH_Dev and SourceLH_Test lakehouses in the Source LHs with Variables workspace.

Create a variable library with variables

Now, create the variable library:

  1. In the Source LHs with Variables workspace, select New item.

  2. Under Develop data, select Variable library (preview).

    Screenshot that shows the tile for creating a variable library.

  3. Name the library WS variables, and then select Create.

  4. Select New variable.

    Screenshot that shows the button for selecting a new variable.

  5. Create the following variables:

    Name Type Default value set
    Source_LH String <GUID of SourceLH_Stage lakehouse>
    Source_WSID String <GUID of SourceLH_Stage workspace>
    Destination_LH String <GUID of SourceLH_Dev lakehouse>
    Destination_WSID String <GUID of SourceLH_Dev workspace>
    SourceTable_Name String Processed
    DestinationTable_Name String DevCopiedData

    Screenshot of the finished default set for the variable library.

  6. Select Save.

Create alternate value sets

In these steps, you add the alternate value sets to your variable library:

  1. Create the first value set:

    1. In the WS Variables variable library, select Add value set.

    2. Enter Test VS for the name, and then select Create.

    3. Create the following variables:

      Name Type Default value set
      Source_LH String <GUID of SourceLH_Dev lakehouse>
      Source_WSID String <GUID of SourceLH_Dev workspace>
      Destination_LH String <GUID of SourceLH_Test lakehouse>
      Destination_WSID String <GUID of SourceLH_Test workspace>
      SourceTable_Name String DevCopiedData
      DestinationTable_Name String TestCopiedData
    4. Select Save > Agree.

  2. Create the second value set:

    1. Select Add value set.

    2. Enter Prod VS for the name, and then select Create.

    3. Create the following variables:

      Name Type Default value set
      Source_LH String <GUID of SourceLH_Test lakehouse>
      Source_WSID String <GUID of SourceLH_Test workspace>
      Destination_LH String <GUID of SourceLH_Prod lakehouse>
      Destination_WSID String <GUID of SourceLH_Prod workspace>
      SourceTable_Name String TestCopiedData
      DestinationTable_Name String ProdCopiedData

      Screenshot of the finished alternate values in a variable library.

    4. Select Save > Agree.

Create the Pipeline_Deploy pipeline and declare variables

In these steps, you create your pipeline and declare your variables:

  1. In the Source LHs with Variables workspace, select New item.

  2. Under Get data, select Data pipeline.

    Screenshot of the tile for a data pipeline.

  3. Enter the name Pipeline_Deploy, and then select Create.

  4. Select Copy data > Add to canvas.

    Screenshot of menu selections for adding copy data to a canvas.

  5. Select the canvas so that the focus is off Copy data.

  6. Select Library variables (preview).

    Screenshot of the tab for library variables.

  7. Select New, and then add the following variables:

    Name Library Variable name Type
    SourceLH WS Variables Source_LH String
    SourceWSID WS Variables Source_WSID String
    DestinationLH WS Variables Destination_LH String
    DestinationWSID WS Variables Destination_WSID String
    SourceTableName WS Variables SourceTable_Name String
    DestinationTableName WS Variables DestinationTable_Name String

    Screenshot of adding variables to a pipeline.

  8. Select Save.

Configure the source connection for the Pipeline_Deploy pipeline

In these steps, you configure the source connection for your pipeline:

  1. In the Source LHs with Variables workspace, go to Pipeline_Deploy.

  2. On the canvas, select Copy data so that the focus is on Copy data.

  3. Select Source.

  4. Configure SourceLH:

    1. Under Source > Connection, select Add dynamic content.

    2. Select the ellipsis (...), and then select Library variables (preview).

    3. Select SourceLH. It populates the box with @pipeline().libraryVariables.SourceLH. Select OK.

      Screenshot of the pane for adding dynamic content for a connection source.

  5. Configure SourceWSID:

    1. Under Source > Workspace ID, select Add dynamic content.

    2. Select the ellipsis (...), and then select Library variables (preview).

    3. Select SourceWSID. It populates the box with @pipeline().libraryVariables.SourceWSID. Select OK.

      Screenshot of the pane for adding dynamic content for a workspace source.

  6. Configure SourceTableName:

    1. Under Source > Table, select Enter manually, select Table name, and then select Add dynamic content.

    2. Select the ellipsis (...), and then select Library variables (preview).

    3. Select SourceTableName. It populates the box with @pipeline().libraryVariables.SourceTableName. Select OK.

      Screenshot of the pane for adding dynamic content for a table name.

  7. Now that the source connection is set up, you can test it. Select Preview data, and then select OK on the flyout. After the data is populated, you can close the data preview.

    Screenshot of the data preview for a source connection.

Configure the destination connection for the Pipeline_Deploy pipeline

In these steps, you configure the destination connection for your pipeline:

  1. In the Source LHs with Variables workspace, go to Pipeline_Deploy.

  2. On the canvas, select Copy data so that the focus is on Copy data.

  3. Select Destination.

  4. Configure SourceLH:

    1. Under Destination > Connection, select Add dynamic content.

    2. Select the ellipsis (...), and then select Library variables (preview).

    3. Select SourceLH. It populates the box with @pipeline().libraryVariables.DestinationLH. Select OK.

      Screenshot of the pane for adding dynamic content for a connection destination.

  5. Configure DestinationWSID:

    1. Under Destination > Workspace ID, select Add dynamic content.

    2. Select the ellipsis (...), and then select Library variables (preview).

    3. Select DestinationWSID. It populates the box with @pipeline().libraryVariables.DestinationWSID. Select OK.

      Screenshot of the pane for adding dynamic content for a workspace destination.

  6. Configure DestinationTableName:

    1. Under Destination > Table, select Enter manually, select Table name, and then select Add dynamic content.

    2. Select the ellipsis (...), and then select Library variables (preview).

    3. Select DestinationTableName. It populates the box with @pipeline().libraryVariables.DestinationTableName. Select OK.

      Screenshot of the pane for adding dynamic content for a destination table name.

  7. Now that the destination connection is set up, save the pipeline and select Run. Confirm that it successfully runs.

    Screenshot of a pipeline run.

Create the deployment pipeline

Now, create your deployment pipeline:

  1. In the Source LHs with Variables workspace, select Create deployment pipeline.

  2. Name the pipeline Deployment_Pipeline_Var, and then select Next.

    Screenshot of the pane for naming a new deployment pipeline.

  3. In the deployment pipeline, select Create and continue.

    Screenshot that shows the button for creating a deployment pipeline.

  4. For the Development stage:

    1. In the dropdown list, select Source LHs with Variables for the workspace. Then select the Assign check mark.

      Screenshot of selecting the workspace for a new deployment pipeline.

    2. Select Continue. The stage should now be populated with the items from the workspace.

      Screenshot of the development part of a deployment pipeline.

  5. For the Test stage:

    1. Select the checkbox at the top to select all items. Then clear the checkbox for the SourceLH_Dev lakehouse.

    2. Select the Deploy button. Select Deploy again. The Test stage should now be populated.

      Screenshot of the test part of a new deployment pipeline.

  6. For the Production stage:

    1. Select the checkbox at the top to select all items. Then clear the checkbox for the SourceLH_Test lakehouse.

    2. Select the Deploy button. Select Deploy again. The Production stage should now be populated.

      Screenshot of the production part of a new deployment pipeline.

Set the variable library's active set for each stage

In these steps, you configure the active set for each stage in your deployment pipeline:

  1. Configure the active set for the Test stage:

    1. On the sidebar, select the Deployment_Pipeline_Var pipeline.

    2. Select the Test stage.

      Screenshot of the test stage.

    3. Select WS Variables.

    4. Select the ellipsis (...), and then select Set as active. Select the Set as Active button.

      Screenshot of a variable library, with selections for setting the test stage as active.

      The active set is now configured.

      Screenshot of a configured active set in a deployment pipeline.

    5. Select Save > Agree.

  2. Configure the active set for the Prod stage:

    1. On the sidebar, select the Deployment_Pipeline_Var pipeline.

    2. Select the Prod stage.

    3. Select WS Variables.

    4. Select the ellipsis (...), and then select Set as active. Select the Set as Active button.

    5. Select Save > Agree.

Verify and test the variable library

Now that you set up the variable library and configured all of the active sets for each stage of the deployment pipeline, you can verify them:

  1. Check the SourceLHs_Dev lakehouse:

    1. In the Source LHs with Variables workspace, select the SourceLHs_Dev lakehouse.

    2. Change the connection from Lakehouse to SQL analytics endpoint.

    3. In the explorer, expand Schemas > dbo > Tables.

    4. Confirm that the DevCopiedData table appears.

      Screenshot of the area for tables in the explorer.

  2. Switch to the SourceLHs_Test lakehouse and repeat the preceding steps.

    The TestCopiedData table shouldn't appear because you haven't run the pipeline yet with the Test VS active set.

  3. Switch to the SourceLHs_Prod lakehouse and repeat the preceding steps.

    The ProdCopiedData table shouldn't appear because you haven't run the pipeline yet with the Prod VS active set.

  4. Check the Test stage of the Deployment_Pipeline_Var pipeline:

    1. Switch to the Deployment_Pipeline_Var pipeline and select the Test stage.

    2. Select the Pipeline_Deploy pipeline.

    3. Select Run. This process should finish successfully.

  5. Check the SourceLHs_Test lakehouse again:

    1. Switch to the SourceLHs_Test lakehouse.

    2. Change the connection from Lakehouse to SQL analytics endpoint.

    3. In the explorer, expand Schemas > dbo > Tables.

    4. Confirm that the TestCopiedData table appears.

      Screenshot of the area for tables and a data preview in the explorer.

  6. Check the Production stage of the Deployment_Pipeline_Var pipeline:

    1. Switch to the Deployment_Pipeline_Var pipeline and select the Production stage.

    2. Select the Pipeline_Deploy pipeline.

    3. Select Run. This process should finish successfully.

  7. Check the SourceLHs_Prod lakehouse again:

    1. Switch to the SourceLHs_Prod lakehouse.

    2. Change the connection from Lakehouse to SQL analytics endpoint.

    3. In the explorer, expand Schemas > dbo > Tables.

    4. Confirm that the ProdCopiedData table appears.

Customize the variable values in Git (optional)

To see how the variable library is represented in Git, or to edit the variables from a Git repository:

  1. In the workspace, select Source control and connect the workspace to a Git repository.

  2. On the Source control pane, select Commit to push the workspace content to the Git repository.

    The Git repo has a folder for each item in the workspace. A folder called WS variables.VariableLibrary represents the variable library item. For more information about the contents of this folder, see Variable library CI/CD.

  3. Compare the ProdVS.json and TestVS.json files in the valueSets folder. Confirm that the overrides variable is set to the different values. You can edit these values directly in the UI or by editing this file in Git and updating it to the workspace.

    {
     "$schema": "https://developer.microsoft.com/json-schemas/fabric/item/VariablesLibrary/definition/valueSets/1.0.0/schema.json",
     "valueSetName": "Test VS",
     "overrides": [
      {
       "name": "Source_LH",
       "value": "4fe228d3-a363-4b7f-a5d4-fae9d2abca43"
      },
      {
       "name": "DestinationTableName",
       "value": "TestCopiedData"
      }
     ]
    }
    
    {
     "$schema": "https://developer.microsoft.com/json-schemas/fabric/item/VariablesLibrary/definition/valueSets/1.0.0/schema.json",
     "valueSetName": "Prod VS",
     "overrides": [
      {
       "name": "Source_LH",
       "value": "c0f13027-9bf4-4e8c-8f57-ec5c18c8656b"
      },
      {
       "name": "DestinationTableName",
       "value": "ProdCopiedData"
      }
     ]
    }