【问题标题】:(How) are variable groups versioned in Azure DevOps?(如何)在 Azure DevOps 中对变量组进行版本控制?
【发布时间】:2020-11-03 15:58:31
【问题描述】:

我一直在尝试查找一些关于变量组在 Azure DevOps 中是如何进行版本控制的信息(或者它们是否完全被版本控制)。

我的“问题”是如果我们有以下情况怎么办:

我们有一个发布管道,其中包含一个链接变量组,其中包含一组发布所依赖的变量。

在我们第一次运行发布管道(发布 1)期间,我们部署应用程序并使用变量组变量来配置应用程序。

在我们第一次发布后,一切正常,几周过去了,我们决定对变量组进行一些更改。例如,我们可能会更改变量的名称,或更改值。现在我们已经为下一个版本(版本 2)做好了准备。

我们运行我们的版本,但只是发现有什么东西坏了,应用程序不再工作了..所以我们很快想回滚到前一个阶段(到版本 1),所以我们只是“重新-发布/重新运行“我们为发布 1 所做的发布...但是.. 由于我们更改了变量组变量,这是否会导致我们使用新更新的变量进行发布,或者 Azure DevOps 是否以某种方式存储/”快照”从第一次发布开始的变量组的阶段?

【问题讨论】:

  • 为什么会被否决?海事组织这是一个完全有效的问题..无论如何..我会自己回答它..

标签: variables azure-devops release azure-pipelines-release-pipeline


【解决方案1】:

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

【讨论】:

  • 如果我们将秘密保存在变量组中呢?看起来我们也将它们保存在我们的回购中。或者az pipelines variable-group list 不会以纯文本形式返回它们?
  • @KrzysztofMadej 我不知道,我没有尝试过秘密......
【解决方案2】:

Azure DevOps 不会对变量组进行版本控制,因为如果您更改变量会创建组本身的新修订版。但是,要回答我自己的问题.. 它确实会在构建和发布之间保留变量值和名称。 因此,例如,如果变量在版本 1 和版本 2 之间发生更改,并且我们重新运行版本 1 的部署,则变量将与您第一次运行版本 1 时完全相同。无论进行了哪些更改到变量组或任何其他发布/阶段/构建变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-20
    • 2020-05-26
    • 1970-01-01
    • 2018-10-02
    • 1970-01-01
    • 1970-01-01
    • 2017-03-22
    • 2011-10-13
    相关资源
    最近更新 更多