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

如何在Azure ML管道中参数化Azure订阅名称实现统一配置?

Azure ML管道订阅名称参数化方案

完全可以实现订阅名称的统一配置,不用逐个修改每个AzureCLI任务里的硬编码值,下面提供两种常用的实现方式:

方案1:使用管道变量(适合固定/变量组管理场景)

在管道的variables块中定义订阅名称变量,后续所有AzureCLI任务直接引用该变量即可。如果需要统一管理多个环境的订阅,还可以把这个变量放到变量组中,只需在variables块引入变量组即可。

修改后的完整管道代码:

trigger: 
  none

schedules:
- cron: "0 12 * * *"
  displayName: 每日构建
  branches:
    include:
    - dev
  always: true
pool:
  vmImage: "windows-latest"

variables:
  - group: ml-environment
  # 新增订阅名称变量
  - name: azureSubscriptionName
    value: 'MYSUB'

steps:
- task: UsePythonVersion@0
  displayName: 使用Python 3.8
  inputs:
    versionSpec: '3.8'
    addToPath: true 

# 调用Python脚本(引用统一变量)
- task: AzureCLI@2
  inputs:
    azureSubscription: '$(azureSubscriptionName)'
    scriptType: 'batch'
    scriptLocation: 'inlineScript'
    inlineScript: 'python etl.py'
    workingDirectory: wd/scripts

# 调用另一个Python脚本(同样引用统一变量)
- task: AzureCLI@2
  inputs:
    azureSubscription: '$(azureSubscriptionName)'
    scriptType: 'batch'
    scriptLocation: 'inlineScript'
    inlineScript: 'python example.py'
    workingDirectory: wd/scripts

方案2:使用管道参数(适合触发时动态指定场景)

如果需要在手动触发管道时灵活选择或输入订阅名称,可以在管道顶部定义参数,任务中直接引用参数值。这种方式允许触发时覆盖默认值,更灵活。

修改后的完整管道代码:

# 新增参数定义块
parameters:
  - name: azureSubscription
    type: string
    default: 'MYSUB' # 默认订阅名称

trigger: 
  none

schedules:
- cron: "0 12 * * *"
  displayName: 每日构建
  branches:
    include:
    - dev
  always: true
pool:
  vmImage: "windows-latest"

variables:
  - group: ml-environment

steps:
- task: UsePythonVersion@0
  displayName: 使用Python 3.8
  inputs:
    versionSpec: '3.8'
    addToPath: true 

# 调用Python脚本(引用管道参数)
- task: AzureCLI@2
  inputs:
    azureSubscription: '${{ parameters.azureSubscription }}'
    scriptType: 'batch'
    scriptLocation: 'inlineScript'
    inlineScript: 'python etl.py'
    workingDirectory: wd/scripts

# 调用另一个Python脚本(同样引用管道参数)
- task: AzureCLI@2
  inputs:
    azureSubscription: '${{ parameters.azureSubscription }}'
    scriptType: 'batch'
    scriptLocation: 'inlineScript'
    inlineScript: 'python example.py'
    workingDirectory: wd/scripts

两种方式的区别

  • 管道变量:值固定(或从变量组读取),适合不需要频繁变更订阅的场景,维护更集中。
  • 管道参数:支持手动触发时动态修改,适合需要切换不同订阅执行管道的场景,灵活性更高。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 10:35:20