我在 azure 上有两个环境。它们之间的区别之一只是来自变量组的环境变量。是否可以为一个管道动态设置组名称,而不是设置两个可以映射自己的组变量的管道?
这是我的构建管道的示例
trigger:
- master
- develop
jobs:
- job: DefineVariableGroups
steps:
- script: |
if [ $(Build.SourceBranch) = 'refs/heads/master' ]; then
echo "##vso[task.setvariable variable=group_name_variable;isOutput=true]beta_group"
elif [ $(Build.SourceBranch) = 'refs/heads/develop' ]; then
echo "##vso[task.setvariable variable=group_name_variable;isOutput=true]alpha_group"
fi
name: 'DefineVariableGroupsTask'
- script: echo $(DefineVariableGroupsTask.group_name_variable)
name: echovar # that works.
- job: Test
dependsOn: DefineVariableGroups
pool:
vmImage: 'Ubuntu-16.04'
variables:
- group: $[ dependencies.DefineVariableGroups.outputs['DefineVariableGroupsTask.group_name_variable'] ]
# that doesn't work. Error here
steps:
- script: echo $(mode)
displayName: 'test'
您可以使用的一种方法或解决方法是使用模板。
我确信最好的选择是动态使用“组变量”的可能性,虽然我相信这是一种选择,但这是不可能的。
trigger:
tags:
include:
- develop
- qa
- production
variables:
- name: defaultVar
value: 'value define yml on project repo'
- group: variables-example-outside
resources:
repositories:
- repository: yml_reference
type: github
ref: refs/heads/yml_reference
name: enamba/azure_devops
endpoint: enamba
jobs:
- ${{ if eq(variables['Build.SourceBranch'], 'refs/tags/develop') }}:
- template: deploy.example.yml@yml_reference
parameters:
GroupVariablesName: variables-example-developer
- ${{ if eq(variables['Build.SourceBranch'], 'refs/tags/qa') }}:
- template: deploy.example.yml@yml_reference
parameters:
GroupVariablesName: variables-example-qa
- ${{ if eq(variables['Build.SourceBranch'], 'refs/tags/production') }}:
- template: deploy.example.yml@yml_reference
parameters:
GroupVariablesName: variables-example-production
模板内部:
parameters:
GroupVariablesName: ''
jobs:
- job: deploy_app
displayName: 'Deploy application'
variables:
- group: ${{ parameters.GroupVariablesName }}
- group: variables-example-inside
steps:
- script: |
echo outsidevar '$(outsidevar)'
echo defaultVar '$(defaultVar)'
echo var by tag '$(variable)'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)