LinuxCommandLibrary

az-repos

Manage Azure DevOps Git repositories

TLDR

List all repos in a specific project

$ az repos list [[-p|--project]] [project_name]
copy

Add policy on a specific branch of a specific repository to restrict basic merge
$ az repos policy merge-strategy create --repository-id [repository_id_in_repos_list] --branch [branch_name] --blocking --enabled --allow-no-fast-forward false --allow-rebase true --allow-rebase-merge true --allow-squash true
copy

Add build validation on a specific repository, using an existing build pipeline, to be triggered automatically on source update
$ az repos policy build create --repository-id [repository_id] --build-definition-id [build_pipeline_id] --branch main --blocking --enabled --queue-on-source-update-only true --display-name [name] --valid-duration [minutes]
copy

List all active Pull Requests on a specific repository within a specific project
$ az repos pr list [[-p|--project]] [project_name] [[-r|--repository]] [repository_name] --status active
copy

SYNOPSIS

az repos <subcommand> [options]

Common subcommands include:
az repos create --name <repository-name> [--org <organization-url>] [--project <project-name>]
az repos list [--org <organization-url>] [--project <project-name>]
az repos show --id <repository-id-or-name> [--org <organization-url>] [--project <project-name>]
az repos delete --id <repository-id-or-name> [--org <organization-url>] [--project <project-name>] [--yes]
az repos policy <policy-subcommand> [options]
az repos pr <pr-subcommand> [options]

PARAMETERS

--org | --organization
    Specifies the Azure DevOps organization URL (e.g., https://dev.azure.com/myorganization). Applicable to most subcommands.

--project | --p
    Specifies the name or ID of the Azure DevOps project. Applicable to most subcommands.

--id
    The ID or name of the repository. Required for operations targeting a specific repository (e.g., show, delete, update).

--name
    The name of the repository. Used when creating a new repository or updating an existing one.

--default-branch
    Sets the default branch for a repository (e.g., main, master). Used with az repos update.

--detect {true, false}
    Automatically detect organization and project from Git configuration. Default is true.

--output {json, jsonc, table, tsv, yaml, none}
    Specify the output format for the command results. Defaults to json.

--query
    A JMESPath query string used to filter the output of the command.

--help
    Show help message for the command or subcommand.

DESCRIPTION

The az repos command group, part of the Azure Command-Line Interface (Azure CLI), provides a robust set of tools for managing Git repositories within Azure DevOps. It enables users to interact programmatically with repositories, branches, pull requests, and policies directly from the command line. This group is fundamental for automating various repository management tasks, scripting continuous integration/continuous delivery (CI/CD) pipelines, and integrating with other systems.

Users can perform operations such as listing existing repositories, creating new ones, updating repository settings, managing branches, configuring critical branch policies (e.g., minimum reviewers, build validation), and handling pull requests. The az repos commands leverage the Azure DevOps REST APIs, offering a powerful way to manage version control and collaborative development within Azure DevOps organizations. It requires an authenticated Azure CLI session and appropriate permissions within Azure DevOps to function correctly, making it an indispensable tool for developers and DevOps engineers working with Azure DevOps services.

CAVEATS

The az repos command group is not a standalone executable but a collection of subcommands within the Azure CLI. It requires the Azure CLI to be installed and configured. Operations necessitate proper authentication (e.g., via az login or Personal Access Token) and sufficient permissions within the targeted Azure DevOps organization and project. Users must specify a subcommand (like list, create, policy, pr) to perform any action.

AUTHENTICATION

Most az repos operations require authentication to your Azure DevOps organization. This is typically achieved using az login for interactive browser-based authentication or by configuring a Personal Access Token (PAT) as a non-interactive authentication method, suitable for scripting and automation.

CONTEXT AND DEFAULTS

To simplify command usage, you can set default organization and project values using az devops configure or by setting environment variables (AZURE_DEVOPS_ORG, AZURE_DEVOPS_PROJECT). This eliminates the need to specify the --org and --project parameters with every command, making your scripts more concise.

SUBCOMMAND STRUCTURE

The az repos command is a *group* that contains numerous *subgroups* (e.g., az repos policy, az repos pr) and direct *commands* (e.g., az repos list, az repos create). To execute an action, you must always append a specific subcommand or navigate through subgroups to the desired command. For example, to manage pull request policies, you would use az repos policy pr.

HISTORY

The Azure CLI, developed by Microsoft, provides a cross-platform command-line interface for managing Azure resources. The functionality for Azure DevOps, including the az repos command group, was initially introduced as an extension (azure-devops) to the core CLI. Its integration into the main CLI reflects the increasing importance of automating Azure DevOps tasks and the demand for programmatic interaction with CI/CD pipelines and version control systems. The ongoing development of az repos aligns with modern DevOps practices, Infrastructure as Code (IaC), and GitOps principles, allowing for seamless integration and automation of repository management within the Azure ecosystem.

SEE ALSO

az login, az configure, az devops, git(1), ssh(1)

Copied to clipboard