Azure Pipeline - 使用模板任务中的变量集作为另一个模板任务中的参数
Azure Pipeline - Use variable set in template task as a parameter in another template task
我创建了两个模板 -- 一个用于获取和设置一些配置,例如区域名称,另一个用于部署。我正在尝试使用配置模板任务中设置的变量作为部署模板的参数输入。有实际的方法吗?
我的配置模板:
steps:
- task: AzureCLI@2
name: Config
displayName: Get Config and Generate Variables
inputs:
azureSubscription: '$(Subscription)'
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
Environment="prod"
echo "##vso[task.setvariable variable=Environment;isOutput=true]prod"
echo "##vso[task.setvariable variable=EastName;isOutput=true]$(AppNamePrefix)-$Environment-eastus"
echo "##vso[task.setvariable variable=East2Name;isOutput=true]$(AppNamePrefix)-$Environment-eastus2"
echo "##vso[task.setvariable variable=CentralName;isOutput=true]$(AppNamePrefix)-$Environment-centralus"
echo "##vso[task.setvariable variable=WestName;isOutput=true]$(AppNamePrefix)-$Environment-westus"
我的部署模板如下所示:
parameters:
- name: artifactName
type: string
default: MyBuildOutputs
- name: appFullName
type: string
- name: condition
type: boolean
default: true
steps:
- task: AzureFunctionApp@1
condition: ${{ parameters.condition }}
displayName: 'Production deploy'
inputs:
azureSubscription: '$(Subscription)'
appType: 'functionApp'
appName: ${{ parameters.appFullName }}
package: '$(System.ArtifactsDirectory)/${{ parameters.artifactName }}/$(Build.BuildId).zip'
deploymentMethod: 'auto'
我的舞台看起来像这样(删除了不必要的位):
- template: ../../tasks/azure/getConfig.yml
- template: ../../tasks/azure/deployToFA.yml
parameters:
appFullName: $(EastName)
我已经为 appFullName: <name>
尝试了以下方法:
$(EastName)
${{ EastName }}
$[ EastName ]
$EastName
但是,遗憾的是,其中 none 似乎可以正常工作,因为它们都作为文字被引入。有没有办法做到这一点?我已经看到使用 dependsOn
的方法,但我不希望两个模板之间存在隐藏的依赖关系(如果可能的话)
but, sadly, none of these seem to work as they all get pulled in as
literals. Is there a way of doing this? I have seen ways of using
dependsOn but I don't want the hidden dependency between the two
templates (if that's even possible)
抱歉,恐怕目前不支持您的模板结构。您可以查看 Process the pipeline:
要将管道变成 运行,Azure Pipelines 按以下顺序执行几个步骤:
首先,展开模板并对模板表达式求值。
因此 deploy template
中的 ${{ parameters.appFullName }}
在 之前 config template
运行 评估 AzureCli 任务。这就是 none of these seem to work as they all get pulled in as literals
的原因。按照设计,您的 $(EastName)
(运行time 变量) 在传递给参数时没有任何意义。
作为替代方法,检查Use variables as task inputs。它描述了满足您需求的另一种方式。
您的配置模板:
steps:
- task: AzureCLI@2
name: Config
displayName: Get Config and Generate Variables
inputs:
xxx
您的部署模板:
parameters:
- name: artifactName
type: string
default: MyBuildOutputs
- name: appFullName
type: string
- name: condition
type: boolean
default: true
steps:
- task: AzureFunctionApp@1
condition: ${{ parameters.condition }}
displayName: 'Production deploy'
inputs:
azureSubscription: '$(Subscription)'
appType: 'functionApp'
appName: $(Config.EastName) // Changes here. ********* Config is the name of your AzureCLI task.
package: '$(System.ArtifactsDirectory)/${{ parameters.artifactName }}/$(Build.BuildId).zip'
deploymentMethod: 'auto'
你的舞台:
- template: ../../tasks/azure/getConfig.yml
- template: ../../tasks/azure/deployToFA.yml
希望对您有所帮助。
我创建了两个模板 -- 一个用于获取和设置一些配置,例如区域名称,另一个用于部署。我正在尝试使用配置模板任务中设置的变量作为部署模板的参数输入。有实际的方法吗?
我的配置模板:
steps:
- task: AzureCLI@2
name: Config
displayName: Get Config and Generate Variables
inputs:
azureSubscription: '$(Subscription)'
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
Environment="prod"
echo "##vso[task.setvariable variable=Environment;isOutput=true]prod"
echo "##vso[task.setvariable variable=EastName;isOutput=true]$(AppNamePrefix)-$Environment-eastus"
echo "##vso[task.setvariable variable=East2Name;isOutput=true]$(AppNamePrefix)-$Environment-eastus2"
echo "##vso[task.setvariable variable=CentralName;isOutput=true]$(AppNamePrefix)-$Environment-centralus"
echo "##vso[task.setvariable variable=WestName;isOutput=true]$(AppNamePrefix)-$Environment-westus"
我的部署模板如下所示:
parameters:
- name: artifactName
type: string
default: MyBuildOutputs
- name: appFullName
type: string
- name: condition
type: boolean
default: true
steps:
- task: AzureFunctionApp@1
condition: ${{ parameters.condition }}
displayName: 'Production deploy'
inputs:
azureSubscription: '$(Subscription)'
appType: 'functionApp'
appName: ${{ parameters.appFullName }}
package: '$(System.ArtifactsDirectory)/${{ parameters.artifactName }}/$(Build.BuildId).zip'
deploymentMethod: 'auto'
我的舞台看起来像这样(删除了不必要的位):
- template: ../../tasks/azure/getConfig.yml
- template: ../../tasks/azure/deployToFA.yml
parameters:
appFullName: $(EastName)
我已经为 appFullName: <name>
尝试了以下方法:
$(EastName)
${{ EastName }}
$[ EastName ]
$EastName
但是,遗憾的是,其中 none 似乎可以正常工作,因为它们都作为文字被引入。有没有办法做到这一点?我已经看到使用 dependsOn
的方法,但我不希望两个模板之间存在隐藏的依赖关系(如果可能的话)
but, sadly, none of these seem to work as they all get pulled in as literals. Is there a way of doing this? I have seen ways of using dependsOn but I don't want the hidden dependency between the two templates (if that's even possible)
抱歉,恐怕目前不支持您的模板结构。您可以查看 Process the pipeline:
要将管道变成 运行,Azure Pipelines 按以下顺序执行几个步骤: 首先,展开模板并对模板表达式求值。
因此 deploy template
中的 ${{ parameters.appFullName }}
在 之前 config template
运行 评估 AzureCli 任务。这就是 none of these seem to work as they all get pulled in as literals
的原因。按照设计,您的 $(EastName)
(运行time 变量) 在传递给参数时没有任何意义。
作为替代方法,检查Use variables as task inputs。它描述了满足您需求的另一种方式。
您的配置模板:
steps:
- task: AzureCLI@2
name: Config
displayName: Get Config and Generate Variables
inputs:
xxx
您的部署模板:
parameters:
- name: artifactName
type: string
default: MyBuildOutputs
- name: appFullName
type: string
- name: condition
type: boolean
default: true
steps:
- task: AzureFunctionApp@1
condition: ${{ parameters.condition }}
displayName: 'Production deploy'
inputs:
azureSubscription: '$(Subscription)'
appType: 'functionApp'
appName: $(Config.EastName) // Changes here. ********* Config is the name of your AzureCLI task.
package: '$(System.ArtifactsDirectory)/${{ parameters.artifactName }}/$(Build.BuildId).zip'
deploymentMethod: 'auto'
你的舞台:
- template: ../../tasks/azure/getConfig.yml
- template: ../../tasks/azure/deployToFA.yml
希望对您有所帮助。