通过 CLI 停止所有 Azure 数据工厂触发器

Stop all Azure Data Factory triggers through CLI

我正在尝试通过 Azure CLI 部署 ARM 模板,如下所示:

az deployment group create --name APP-ADF-Template --resource-group <my-resource-group> --template-file ./pipelines/app_arm.json --parameters ./pipelines/app_stage_arm_params.json

但是当任何触发处于 Start 状态时出现错误。

ERROR: Deployment failed. Correlation ID: 10c0ee19-1452-41ce-8edd-4ecf33499f25. {
  "error": {
    "code": "TriggerEnabledCannotUpdate",
    "message": "Cannot update enabled Trigger; the trigger needs to be disabled first. ",
    "target": null,
    "details": null
  }
}

我们可以用下面的命令来停止一个一个的触发器。

az datafactory trigger stop --factory-name <my-data-factory> --resource-group <my-resource-group> --trigger-name <my-trigger-1>

像这样我们有10多个触发器,很难一一停止。有什么方法可以一次停止所有这些并启动所有这些post部署成功吗?

没有这种方法可以同时停止所有触发器,在这种情况下,您的选择是使用循环。

停止所有触发器:

对于Windows:

$names = az datafactory trigger list --factory-name "xxx" --resource-group "xxx" --query "[?properties.runtimeState=='Started'].name" -o tsv --only-show-errors
foreach($name in $names){
    az datafactory trigger stop --factory-name "xxx" --resource-group "xxx" --name $name --only-show-errors
}

对于 Unix

names=`az datafactory trigger list --factory-name "xxx" --resource-group "xxx" --query "[?properties.runtimeState == 'Started'].name" -o tsv --only-show-errors`
                    
for name in ${names[@]}; 
do
    echo "Stopping the trigger : ${name}"
    az datafactory trigger stop --factory-name "xxx" --resource-group "xxx" --name ${name} --only-show-errors
done

部署后,启动所有触发器:

对于Windows:

$names = az datafactory trigger list --factory-name "xxx" --resource-group "xxx" --query "[?properties.runtimeState=='Stopped'].name" -o tsv --only-show-errors
foreach($name in $names){
    az datafactory trigger start --factory-name "xxx" --resource-group "xxx" --name $name --only-show-errors
}

对于 Unix

names=`az datafactory trigger list --factory-name "xxx" --resource-group "xxx" --query "[?properties.runtimeState == 'Stopped'].name" -o tsv --only-show-errors`
                    
for name in ${names[@]}; 
do
    echo "Starting the trigger : ${name}"
    az datafactory trigger start --factory-name "xxx" --resource-group "xxx" --name ${name} --only-show-errors
done