You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从ADLS触发Azure Pipeline以部署MS Fabric资源

实现ADLS文件变更触发MS Fabric CI/CD流水线

整体逻辑

ADLS无法直接触发Azure DevOps流水线,需通过「Azure Event Grid + 中间服务(Azure Function/Logic Apps)」的组合实现:当ADLS容器新增文件时,Event Grid推送事件到中间服务,中间服务调用Azure DevOps流水线API触发部署,同时修改流水线的文件获取逻辑,从ADLS下载Fabric资产文件。


步骤1:配置ADLS事件通知(Event Grid)

  • 登录Azure门户,找到目标ADLS存储账户,进入「事件」选项卡
  • 创建系统主题,选择当前存储账户作为主题源
  • 创建事件订阅:
    • 自定义名称(比如adls-fabric-pipeline-trigger)
    • 事件类型:勾选「Blob创建」「Blob修改」(按需选择)
    • 终结点类型:选择「Azure Function」或「Logic Apps」,关联提前准备好的中间服务
    • 可选过滤:添加规则,比如仅针对目标容器(subject begins with /blobServices/default/containers/你的容器名)、特定文件后缀(data.api.url ends with .json),避免无效触发

步骤2:实现触发流水线的中间服务(以Azure Function为例)

核心逻辑

接收Event Grid的Blob事件,验证有效性后调用Azure DevOps的Run Pipeline API启动流水线。

示例Python代码(Event Grid触发的Function)

import os
import requests
import base64
from azure.eventgrid import EventGridEvent

def main(event: EventGridEvent):
    # 过滤目标容器的事件
    blob_url = event.data.get('url', '')
    if '你的容器名' not in blob_url:
        return 'Skipped: Not target container'
    
    # Azure DevOps配置参数
    org_name = '你的组织名'
    project_name = '你的项目名'
    pipeline_id = '你的流水线ID'
    pat_token = os.environ['AZURE_DEVOPS_PAT']

    # 调用Run Pipeline API
    api_url = f'https://dev.azure.com/{org_name}/{project_name}/_apis/pipelines/{pipeline_id}/runs?api-version=7.1-preview.1'
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Basic {base64.b64encode(f":{pat_token}".encode()).decode()}'
    }
    payload = {
        "resources": {
            "repositories": {
                "self": {
                    "refName": "refs/heads/main"
                }
            }
        }
    }
    
    response = requests.post(api_url, headers=headers, json=payload)
    if response.status_code == 200:
        return f"Pipeline triggered successfully"
    else:
        return f"Trigger failed: {response.text}"

配置注意事项

  • 在Function应用的「配置」中添加AZURE_DEVOPS_PAT应用设置,值为你的Azure DevOps PAT(需授予Build队列权限)
  • 确保Function有网络权限访问Azure DevOps(私有网络环境需配置VNet集成)

步骤3:修改CI/CD流水线的文件获取阶段

替换原拉取Azure Repos的步骤,添加从ADLS下载文件的任务:

示例Azure CLI任务(YAML流水线)

steps:
- task: AzureCLI@2
  displayName: 'Download Fabric files from ADLS'
  inputs:
    azureSubscription: '你的Azure服务连接'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: |
      az storage blob download-batch \
        --source "你的容器名" \
        --destination $(Build.SourcesDirectory) \
        --account-name "你的ADLS存储账户名" \
        --auth-mode login

权限配置

  • 给流水线使用的服务主体(Azure服务连接对应的身份)分配ADLS存储账户的Storage Blob Data Reader角色,确保能读取并下载Blob

步骤4:验证流程

  1. 手动向ADLS目标容器上传一个Fabric资产文件(比如笔记本导出的.json文件)
  2. 检查Event Grid订阅的「监视」选项卡,确认事件已成功推送
  3. 查看Azure Function的日志,确认API调用成功
  4. 登录Azure DevOps,查看流水线是否自动启动并完成Fabric部署

内容的提问来源于stack exchange,提问作者Salman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 22:55:12