Azure WebApp部署任务无法识别变量

时间:2019-08-07 15:52:59

标签: azure-devops azure-pipelines

在管道中运行以下任务时

- task: AzureRmWebAppDeployment@3
  displayName: 'Azure App Service Deploy: Web App'
  inputs:
    azureSubscription: ${{ parameters.azureSubscription }}
    WebAppName: $[dependencies.preDeploy.outputs['webAppName']]
    Package: '$(Pipeline.Workspace)/**/PackageTmp'
    WebAppUri: WebAppUrl
    UseWebDeploy: true
    AdditionalArguments: '-useChecksum'
    RenameFilesFlag: true
    enableXmlVariableSubstitution: true

它抱怨我要分配给WebAppName的变量

##[error]Error: Failed to get resource ID for resource type 'Microsoft.Web/Sites' and resource name '$[dependencies.preDeploy.outputs['webAppName']]'. Error: {"error":{"code":"InvalidFilterInQueryString","message":"Invalid $filter 'resourceType EQ 'Microsoft.Web/Sites' AND name EQ '$[dependencies.preDeploy.outputs['webAppName']]'' specified in the query string."}} (CODE: 400)

为什么变量没有被其实际值替换?

1 个答案:

答案 0 :(得分:0)

您的变量需要使用其引用名称来寻址,该引用名称通常是变量所来自的步骤名称。

  

如果要使变量可用于将来的作业,则必须使用isOutput = true将其标记为输出变量。然后,您可以使用$ []语法并包括设置变量的步骤名称将其映射到将来的作业中。

有关Multi-job Variables

的更多信息

请参见myVarFromJobA: $[ dependencies.A.outputs[' setvarStep .myOutputVar'] ] 在下面的示例中。

jobs:

# Set an output variable from job A
- job: A
  pool:
    vmImage: 'vs2017-win2016'
  steps:
  - powershell: echo "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the value"
    name: setvarStep
  - script: echo $(setvarStep.myOutputVar)
    name: echovar

# Map the variable into job B
- job: B
  dependsOn: A
  pool:
    vmImage: 'ubuntu-16.04'
  variables:
    myVarFromJobA: $[ dependencies.A.outputs['setvarStep.myOutputVar'] ]  # map in the variable
                                                                          # remember, expressions require single quotes
  steps:
  - script: echo $(myVarFromJobA)
    name: echovar