【问题标题】:Azure CLI - VSTS - Yaml - Only the first line of the script seems to be executedAzure CLI - VSTS - Yaml - 似乎只执行了脚本的第一行
【发布时间】:2018-08-12 22:23:37
【问题描述】:

我有以下用于 vsts 的 yaml 构建定义,它应该创建一个 azure 资源组并部署资源。

但是,在创建资源组时,不会部署任何资源。好像脚本的第二行被忽略了。

请注意,如果我单独运行部署脚本行(当资源组存在时),则会部署资源。

steps:
- task: AzureCLI@1
  inputs:
    azureSubscription: 'MySub (xxxxxxxxxxxxxxx)'
    scriptLocation: inlineScript
    inlineScript: |
        az group create -l westeurope -n TestRG
        az group deployment create -g TestRG --mode Incremental --template-file azuredeploy.json --parameters @azuredeploy.parameters.json
    workingDirectory: Test

这里是构建输出:

******************************************************************************
Starting: AzureCLI
******************************************************************************
==============================================================================
Task         : Azure CLI
Description  : Run a Shell or Batch script with Azure CLI commands against an azure subscription
Version      : 1.130.0
Author       : Microsoft Corporation
Help         : [More Information](http://go.microsoft.com/fwlink/?LinkID=827160)
==============================================================================
az group deployment create -g TestRG --mode Incremental --template-file azuredeploy.json --parameters @azuredeploy.parameters.json
C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" login --service-principal -u ******** -p ******** --tenant ********"
[
  {
    "cloudName": "AzureCloud",
    "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "isDefault": true,
    "name": "Test",
    "state": "Enabled",
    "tenantId": "********",
    "user": {
      "name": "********",
      "type": "servicePrincipal"
    }
  }
]
C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" account set --subscription Test"
C:\Windows\system32\cmd.exe /D /S /C ""C:\Users\VSSADM~1\AppData\Local\Temp\azureclitaskscript1520242163645.bat""
D:\a\1\s\Swoon>az group create -l westeurope -n TestRG 
{
  "id": "/subscriptions/xxxxxxxx/resourceGroups/TestRG",
  "location": "westeurope",
  "managedBy": null,
  "name": "TestRG",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null
}
******************************************************************************
Finishing: AzureCLI
******************************************************************************

【问题讨论】:

    标签: yaml azure-pipelines azure-cli


    【解决方案1】:

    您正在使用窗口代理,因此您需要在多个命令前面附加调用以执行所有命令。

    例如:

    call az group create -l westeurope -n TestRG
    call az group deployment create -g TestRG --mode Incremental --template-file azuredeploy.json --parameters @azuredeploy.parameters.json
    

    【讨论】:

    • 感谢这个答案,因为我从未在任何 ms 文档中看到任何提及“呼叫”的内容。此外,当我直观地为 Windows 代理创建构建定义并单击“查看 yaml”时,没有“调用”关键字。
    猜你喜欢
    • 2013-02-04
    • 2020-04-19
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 2015-10-28
    • 2012-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多