Lasīt angliski Rediģēt

Kopīgot, izmantojot


Manage variable groups

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019

This article explains how to create and use variable groups in Azure Pipelines. Variable groups store values and secrets that you can pass into a YAML pipeline or make available across multiple pipelines in a project.

Secret variables in variable groups are protected resources. You can add combinations of approvals, checks, and pipeline permissions to limit access to secret variables in a variable group. Access to nonsecret variables isn't limited by approvals, checks, or pipeline permissions.

Variable groups follow the library security model for roles and permissions.

Prerequisites

  • An Azure DevOps Services organization and project where you have permissions to create pipelines and variables.
  • A project in your Azure DevOps organization or Azure DevOps Server collection. Create a project if you don't have one.
  • If you're using the Azure DevOps CLI, you need Azure CLI version 2.30.0 or higher with the Azure DevOps CLI extension. For more information, see Get started with Azure DevOps CLI.
  • An Azure DevOps Server collection and project where you have permissions to create pipelines and variables.
  • A project in your Azure DevOps organization or Azure DevOps Server collection. Create a project if you don't have one.

Set up the CLI

If you're using the Azure DevOps CLI, you need to set up the CLI to work with your Azure DevOps organization and project.

  1. Sign in to your Azure DevOps organization by using the az login command.

    Azure CLI
    az login
    
  2. If prompted, select your subscription from the list displayed in your terminal window.

  3. Ensure you're running the latest version of the Azure CLI and the Azure DevOps extension by using the following commands.

    Azure CLI
    az upgrade
    az extension add --name azure-devops --upgrade
    
  4. In Azure DevOps CLI commands, you can set the default organization and project by using:

    Azure CLI
    az devops configure --defaults organization=<YourOrganizationURL> project=<Project Name or ID>`
    

    If you haven't set the default organization and project, you can use the detect=true parameter in your commands to automatically detect the organization and project context based on your current directory. If the defaults aren't configured or detected, you need to explicitly specify the org and project parameters in your commands.

Create a variable group

You can create variable groups for the pipeline runs in your project.

Piezīme

To create a secret variable group to link secrets from an Azure key vault as variables, follow the instructions at Link a variable group to secrets in Azure Key Vault.

  1. In your Azure DevOps project, select Pipelines > Library from the left menu.

  2. On the Library page, select + Variable group.

    Screenshot of the Library screen and Add variable group button.

  3. On the new variable group page, under Properties, enter a name and optional description for the variable group.

  4. Under Variables, select + Add, and then enter a variable name and value to include in the group. If you want to encrypt and securely store the value, select the lock icon next to the variable.

  5. Select + Add to add each new variable. When you finish adding variables, select Save.

    Screenshot of configuring and saving a variable group.

You can now use this variable group in project pipelines.

Update variable groups

You can update variable groups by using the Azure Pipelines user interface.

  1. In your Azure DevOps project, select Pipelines > Library from the left menu.
  2. On the Library page, select the variable group you want to update. You can also hover over the variable group listing, select the More options icon, and select Edit from the menu.
  3. On the variable group page, change any of the properties, and then select Save.

Delete a variable group

You can delete variable groups in the Azure Pipelines user interface.

  1. In your Azure DevOps project, select Pipelines > Library from the left menu.
  2. On the Library page, hover over the variable group you want to delete and select the More options icon.
  3. Select Delete from the menu, and then select Delete on the confirmation screen.

Manage variables in variable groups

You can change, add, or delete variables in variable groups by using the Azure Pipelines user interface.

  1. In your Azure DevOps project, select Pipelines > Library from the left menu.
  2. On the Library page, select the variable group you want to update. You can also hover over the variable group listing, select the More options icon, and select Edit from the menu.
  3. On the variable group page, you can:
    • Change any of the variable names or values.
    • Delete any of the variables by selecting the garbage can icon next to the variable name.
    • Change variables to secret or nonsecret by selecting the lock icon next to the variable value.
    • Add new variables by selecting + Add.
  4. After making changes, select Save.

Use variable groups in pipelines

You can use variable groups in YAML or Classic pipelines. Changes that you make to a variable group are automatically available to all the definitions or stages the variable group is linked to.

Use variable groups in Classic pipelines

Classic pipelines can use variable groups without separate authorization. To use a variable group:

  1. Open your Classic pipeline.

  2. Select Variables > Variable groups, and then select Link variable group.

    • In a build pipeline, you see a list of available groups. Select a variable group and select Link. All the variables in the group are available for use within the pipeline.

    • In a release pipeline, you also see a dropdown list of stages in the pipeline. Link the variable group to the pipeline itself, or to one or more specific stages of the release pipeline. If you link to one or more stages, the variables from the variable group are scoped to these stages and aren't accessible in the other stages of the release.

    Screenshot that shows linking a variable group.

When you set a variable with the same name in multiple scopes, the following precedence is used, highest first:

  1. Variable set at queue time
  2. Variable set in the pipeline
  3. Variable set in the variable group

For more information about precedence of variables, see Expansion of variables.

Piezīme

Variables in different groups that are linked to a pipeline in the same scope (for example, job or stage) will collide and the result may be unpredictable. Ensure that you use different names for variables across all your variable groups.