gpt4 book ai didi

azure - 您可以将变量组值传递给 yaml 中的子模板吗?

转载 作者:行者123 更新时间:2023-12-02 22:58:38 25 4
gpt4 key购买 nike

我正在尝试创建一个多级管道,其中为管道的每个阶段定义了变量组。目标是将组中的值作为参数传递给子模板。看来在该阶段定义的组的值没有传递到子模板中。它用空字符串覆盖“DEFAULTVALUE”。

pipeline.yml

trigger:
- none

pool:
name: 'Azure Pipelines'
vmImage: windows-latest

stages:
- stage: DEV
variables:
- group: my-group-dev
jobs:
- template: sub-template.yml
parameters:
env: 'dev'
subscriptionName: '$(SubscriptionName)' # This reference from the variable group doesn't get passed in
subscriptionId: '$(SubscriptionId)'

- stage: TEST
variables:
- group: my-group-test
jobs:
- template: sub-template.yml
parameters:
env: 'test'
subscriptionName: '$(SubscriptionName)' # This reference from the variable group doesn't get passed in
subscriptionId: '$(SubscriptionId)'

子模板.yml

parameters:
env: 'DEFAULTVALUE'
subscriptionName: 'DEFAULTVALUE'
subscriptionId: 'DEFAULTVALUE'

jobs:
- deployment: ResourceDeployment
displayName: Deploy Resources ${{ parameters.env }}
environment: ${{ parameters.env }}
strategy:
runOnce:
deploy:
steps:
- task: AzureFileCopy@4
displayName: 'Upload ARM Templates'
inputs:
sourcePath: '$(Pipeline.Workspace)/templates'
azureSubscription: '${{ parameters.subscriptionName }}'
destination: 'azureBlob'
storage: 'my-storage-account'
containerName: 'arm'
name: AzureFileCopy

- task: AzureResourceManagerTemplateDeployment@3
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: '${{ parameters.subscriptionName }}'
subscriptionId: '${{ parameters.subscriptionId }}'
action: 'Create Or Update Resource Group'
resourceGroupName: 'my-resource-group'
location: 'eastus2'
templateLocation: 'URL of the file'
csmFileLink: '$(AzureFileCopy.StorageContainerUri)${{ parameters.env }}/templates/main.json$(AzureFileCopy.StorageContainerSasToken)'

我还尝试在子模板中添加变量组,但这也无法正确解析...

有人知道这是否可行吗?

最佳答案

已知问题是无法在阶段级别定义的变量组中引用服务连接端点。

您可以通过以下解决方法解决此问题:

1、在全局级别定义变量组,而不是阶段级别 见下文:

trigger:
- none

pool:
name: 'Azure Pipelines'
vmImage: windows-latest

# define the variable group under global level.

variables:
- group: my-group-dev
- group: my-group-test


stages:
- stage: DEV
jobs:
- template: sub-template.yml
parameters:
env: 'dev'
subscriptionName: '$(SubscriptionName)' # This reference from the variable group doesn't get passed in
subscriptionId: '$(SubscriptionId)'

- stage: TEST
jobs:
- template: sub-template.yml
parameters:
env: 'test'
subscriptionName: '$(SubscriptionName)' # This reference from the variable group doesn't get passed in
subscriptionId: '$(SubscriptionId)'

2、在UI页面链接变量组。

在yaml管道编辑页面-->点击3dots-->触发器-->变量选项卡-->链接变量组

enter image description here

enter image description here

请参阅以下主题了解更多信息。

Using a variable for the service connection

Azure subscription endpoint ID cannot be provided through a variable in build definition YAML file

关于azure - 您可以将变量组值传递给 yaml 中的子模板吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65234871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com