【发布时间】:2023-02-16 00:46:47
【问题描述】:
我有一个采用 stepList 的管道模板:
parameters:
- name: applicationDeploySteps
type: stepList
default: []
并将 stepList 注入模板:
- deployment: Deploy_App
displayName: Deploy Application
pool: ${{ variables.AgentPool }}
environment: ${{ parameters.Stage }}
variables:
- name: ServiceConnection
value: SomeServiceConnection
strategy:
runOnce:
deploy:
steps:
- ${{ each step in parameters.applicationDeploySteps }}:
- ${{ each pair in step }}:
${{ pair.key }}: ${{ pair.value }}
但是,我想提供一个 AzureCLI@2 步骤,azureSubscription 参数来自模板编译时 AzureCLI@2 步骤无法访问的变量:
extends:
template: main.yml
parameters:
applicationDeploySteps:
- task: AzureCLI@2
inputs:
azureSubscription: $(ServiceConnection)
addSpnToEnvironment: true
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
echo "do azurey things here"
问题出在azureSubscription: $(ServiceConnection)。显然,该变量无法解决。所以我正在寻找的解决方案是在模板中注入 azureSubscription 值。但是,我找不到一种方法来有效地迭代 input 块中提供的值。
- ${{ each pair in step }}:
${{ pair.key }}: ${{ pair.value }}
让我审问类型的步骤。尝试更进一步只会在尝试对管道进行排队时给我一个空引用异常:
- ${{ each pair in step }}:
${{ if eq(pair.key, 'inputs') }}:
- ${{ each input in pair.value }}:
${{ if eq(input.key, 'azureSubscription') }}:
${{ input.key }}: ${{ variables.ServiceConnection }}
${{ else }}:
${{ input.key }}: ${{ input.value }}
${{ else }}:
${{ pair.key }}: ${{ pair.value }}
那次尝试给了我:Object reference not set to an instance of an object.,没有相应的行号。我猜它无法迭代 pair.value,但我不知道如何进一步解决它或了解我可以迭代和不能迭代的内容。该文档不包含更全面的示例,只是检查它是否是 script 任务并阻止执行。
请注意,this 是相似的,但不是我正在实施的场景。
【问题讨论】:
标签: azure-devops azure-pipelines