(如何)在 Azure DevOps 中对变量组进行版本控制?
(How) are variable groups versioned in Azure DevOps?
我一直在尝试查找有关如何在 Azure DevOps 中对变量组进行版本控制(或者它们是否完全进行了版本控制)的信息。
我的“问题”是如果出现以下情况怎么办:
我们有一个发布管道,它有一个链接变量组,其中包含发布所依赖的一组变量。
在发布管道(第 1 版)的第一个 运行 期间,我们部署了应用程序并使用变量组变量来配置应用程序。
第一次发布后,一切正常,几周过去了,我们决定对我们的变量组进行一些更改。例如,我们可能会更改变量的名称或更改值。现在我们已准备好发布下一个版本(第 2 版)。
我们 运行 我们的版本,但只是发现有些东西坏了,应用程序不再工作了..所以我们想快速回滚到前一个阶段(到版本 1),所以我们只是简单地“re-release/re-run”我们为发布 1 所做的发布......但是..因为我们已经改变了我们的变量组变量,这会导致我们使用新更新的变量进行发布,还是 Azure DevOps以某种方式存储/“快照”第一次发布时变量组的阶段 运行?
Azure DevOps 中的变量组不是版本(还...)。所以,如果你更新一个变量组,你可以知道之前是什么。
但是,作为解决方法,您可以创建一个 Gir 存储库来保存数据并使用自动管道更新他:
trigger: none
schedules:
- cron: "*/15 14-21 * * Mon-Fri"
displayName: Every 15 min M-F 9am-4:45pm (UTC-05:00)
branches:
include:
- master
always: true
- cron: "0 22 * * Mon-Fri"
displayName: M-F 5pm (UTC-05:00)
branches:
include:
- master
always: true
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
persistCredentials: true
clean: true
# Updating the python version available on the linux agent
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
architecture: 'x64'
# Updating pip to latest
- script: python -m pip install --upgrade pip
displayName: 'Upgrade pip'
# Updating to latest Azure CLI version.
- script: pip install --pre azure-cli --extra-index-url https://azurecliprod.blob.core.windows.net/edge
displayName: 'Upgrade Azure CLI'
- script: az --version
displayName: 'Show Azure CLI version'
- script: az extension add -n azure-devops
displayName: 'Install Azure DevOps Extension'
- script: echo ${AZURE_DEVOPS_CLI_PAT} | az devops login
env:
AZURE_DEVOPS_CLI_PAT: $(System.AccessToken)
displayName: 'Login Azure DevOps Extension'
- script: az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project="$(System.TeamProject)"
displayName: 'Set default Azure DevOps organization and project'
- pwsh: |
# Checkout the source branch
git checkout $(Build.SourceBranchName)
# Get all variable groups
$groups = ConvertFrom-Json "$(az pipelines variable-group list)"
$groups | foreach {
$groupName = $_.name
# Prepend VariableGroups folder name
$filePath = Join-Path "VariableGroups" "$groupName.json"
# Save the variable group to a file
ConvertTo-Json $_ | New-Item $filePath -Force
# Use the last modified user's name and email
git config user.email $_.modifiedBy.uniqueName
git config user.name $_.modifiedBy.displayName
# Stage the file
git add $filePath
# Commit
git commit -m "Variable group $groupName updates"
}
# Push all changes
git push origin
displayName: 'Save variable groups'
详细解释你就好here.
Azure DevOps 不会对变量组进行版本控制,因为如果您更改一个变量会创建组本身的新修订版。但是,为了回答我自己的问题……它确实在构建和发布之间保留了变量值和名称。
因此,例如,如果在版本 1 和版本 2 之间更改了变量,并且我们重新 运行 部署版本 1,则变量将与您第一次 运行 版本 1 完全相同。 . 无论对变量组或任何其他 release/stage/build 变量进行了哪些更改。
我一直在尝试查找有关如何在 Azure DevOps 中对变量组进行版本控制(或者它们是否完全进行了版本控制)的信息。
我的“问题”是如果出现以下情况怎么办:
我们有一个发布管道,它有一个链接变量组,其中包含发布所依赖的一组变量。
在发布管道(第 1 版)的第一个 运行 期间,我们部署了应用程序并使用变量组变量来配置应用程序。
第一次发布后,一切正常,几周过去了,我们决定对我们的变量组进行一些更改。例如,我们可能会更改变量的名称或更改值。现在我们已准备好发布下一个版本(第 2 版)。
我们 运行 我们的版本,但只是发现有些东西坏了,应用程序不再工作了..所以我们想快速回滚到前一个阶段(到版本 1),所以我们只是简单地“re-release/re-run”我们为发布 1 所做的发布......但是..因为我们已经改变了我们的变量组变量,这会导致我们使用新更新的变量进行发布,还是 Azure DevOps以某种方式存储/“快照”第一次发布时变量组的阶段 运行?
Azure DevOps 中的变量组不是版本(还...)。所以,如果你更新一个变量组,你可以知道之前是什么。
但是,作为解决方法,您可以创建一个 Gir 存储库来保存数据并使用自动管道更新他:
trigger: none
schedules:
- cron: "*/15 14-21 * * Mon-Fri"
displayName: Every 15 min M-F 9am-4:45pm (UTC-05:00)
branches:
include:
- master
always: true
- cron: "0 22 * * Mon-Fri"
displayName: M-F 5pm (UTC-05:00)
branches:
include:
- master
always: true
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
persistCredentials: true
clean: true
# Updating the python version available on the linux agent
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
architecture: 'x64'
# Updating pip to latest
- script: python -m pip install --upgrade pip
displayName: 'Upgrade pip'
# Updating to latest Azure CLI version.
- script: pip install --pre azure-cli --extra-index-url https://azurecliprod.blob.core.windows.net/edge
displayName: 'Upgrade Azure CLI'
- script: az --version
displayName: 'Show Azure CLI version'
- script: az extension add -n azure-devops
displayName: 'Install Azure DevOps Extension'
- script: echo ${AZURE_DEVOPS_CLI_PAT} | az devops login
env:
AZURE_DEVOPS_CLI_PAT: $(System.AccessToken)
displayName: 'Login Azure DevOps Extension'
- script: az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project="$(System.TeamProject)"
displayName: 'Set default Azure DevOps organization and project'
- pwsh: |
# Checkout the source branch
git checkout $(Build.SourceBranchName)
# Get all variable groups
$groups = ConvertFrom-Json "$(az pipelines variable-group list)"
$groups | foreach {
$groupName = $_.name
# Prepend VariableGroups folder name
$filePath = Join-Path "VariableGroups" "$groupName.json"
# Save the variable group to a file
ConvertTo-Json $_ | New-Item $filePath -Force
# Use the last modified user's name and email
git config user.email $_.modifiedBy.uniqueName
git config user.name $_.modifiedBy.displayName
# Stage the file
git add $filePath
# Commit
git commit -m "Variable group $groupName updates"
}
# Push all changes
git push origin
displayName: 'Save variable groups'
详细解释你就好here.
Azure DevOps 不会对变量组进行版本控制,因为如果您更改一个变量会创建组本身的新修订版。但是,为了回答我自己的问题……它确实在构建和发布之间保留了变量值和名称。 因此,例如,如果在版本 1 和版本 2 之间更改了变量,并且我们重新 运行 部署版本 1,则变量将与您第一次 运行 版本 1 完全相同。 . 无论对变量组或任何其他 release/stage/build 变量进行了哪些更改。