Automating workspace updates using Fabric's 'Update From Git' REST API.
In response to a reader's question, this article outlines my suggested approach to automating workspace updates using Fabric's 'Update From Git' REST API. I’ll explain how to streamline the process with commits pushed to the connected branch.
Setting the stage
I frequently receive questions from readers and viewers about how to optimize and streamline their workflows. Recently, one such question came in that I believe resonates with many people managing workspaces in DevOps environments. Here's the question I received (anonymously, to respect the sender's privacy):
"I have 3 workspaces dev, test, prod, my dev workspace is synced with main branch so when I change something in my pbip file and commit it to main branch, so it shows updates in source control and every time I have to go to workspace and click push button. I want to automate this process. When I was watching your video on Youtube, you ran the pipeline that have already created but which task/step you have added to that pipeline is not clearly mentioned."
This question addresses a common pain point: the need to repeatedly push updates manually in a workspace every time changes are made. In this article, I’ll walk you through my suggested approach to automating this process using Fabric's 'Update From Git' REST API, which updates the workspace with commits pushed to the connected branch. This solution ensures a smoother workflow with less manual intervention.
Watch the demo
For a more detailed explanation and a demo of the functionality described in this article, you can watch the full process in action in my YouTube video...
Solution overview
The solution I propose consists of setting up an Azure DevOps pipeline that runs a PowerShell script to automate the update process via Fabric’s 'Update From Git' REST API. The automation will be triggered upon completion of a pull request (PR) to the branch linked with the workspace.
Here’s a high-level breakdown of the steps:
- Pipeline Configuration: We’ll configure a pipeline in Azure DevOps that will be triggered every time a pull request to the workspace’s linked branch is completed.
- REST API Interaction: The pipeline will execute a PowerShell script that interacts with Fabric's 'Update From Git' API to apply the changes from the Git repository to the workspace.
- Authentication Setup: Since this pipeline will interact with Fabric’s API and the Git repository, we’ll need to handle authentication securely. This can be done either by using tokens stored in an Azure Key Vault or by setting up a user account excluded from Multi-Factor Authentication (MFA).
Setting Up the Pipeline
Let’s walk through the setup process:
- Git Integration Setup:
- Ensure your workspace is properly synced with a Git branch, as the automation will trigger updates from this branch.
- Pipeline Definition:
- Create a new Azure DevOps YAML pipeline that includes a PowerShell script for calling the API. This script will first check the Git status of the workspace to determine if updates are required, then invoke the 'Update From Git' API to apply the changes.
- Handling Authentication:
- To interact with both Fabric and the Git repository, you’ll need tokens or credentials. For the Fabric API, a Power BI access token is required, and for DevOps, a personal access token (PAT) is needed. These can be securely stored in an Azure Key Vault for the pipeline to access during execution.
- Branch Policies:
- The pipeline should be tied to the branch policies of your Git repository so that it’s triggered automatically upon pull request completion. You can restrict the triggers to only fire when relevant files (e.g., Power BI reports) are modified to avoid unnecessary pipeline runs.
Automating the Update
Once the pipeline is in place, here’s how the automation will work:
- A change is introduced to the workspace’s linked Git branch.
- The change is reviewed and merged via a pull request.
- The pipeline is automatically triggered, executing the PowerShell script that calls the 'Update From Git' API.
- The workspace is updated with the changes from the Git branch without any manual intervention.
Key Considerations
- Authentication: The Fabric API currently doesn’t support service principals, so you’ll need to either use a user account or manage tokens securely.
- Workspace Permissions: Ensure the account used for the automation has admin privileges on the workspace to perform the update operation.
Conclusion
This approach allows you to automate the update process, ensuring that your workspaces are always up-to-date with the latest changes from your Git repository. By integrating this automation into your DevOps pipeline, you can eliminate the need for manual intervention and create a smoother workflow for your team.
I hope this solution helps not only the individual who asked the question but also anyone else facing similar challenges. As always, you can find the code and detailed instructions in my repository. Feel free to give it a try and share your feedback!