Azure DevOps CLI 入门

Azure DevOps Services

使用适用于 Azure 命令行接口的 Azure DevOps 扩展 (CLI) ,可以从命令行管理许多Azure DevOps Services。 通过 CLI 命令可使用更快更灵活的交互式画布来简化任务,从而绕过用户界面工作流。

注意

Azure DevOps 命令行接口 (CLI) 仅适用于 Azure DevOps Services。 适用于 Azure CLI 的 Azure DevOps 扩展不支持任何版本的 Azure DevOps Server。

若要开始使用 Azure CLI 的 Azure DevOps 扩展,请执行以下步骤:

  1. 安装 Azure CLI:按照安装 Azure CLI 中的说明设置 Azure CLI 环境。 Azure CLI 版本须至少为 2.10.1。 可以使用 az --version 来验证。

  2. 添加 Azure DevOps 扩展:

     az extension add --name azure-devops
    

    可以使用 az extension listaz extension show --name azure-devops 来确认安装。

  3. 登录:运行 az login 进行登录。 请注意,我们只支持结合使用 az login 与用户名和密码来进行交互或登录。 若要使用个人访问令牌 (PAT) 登录,请参阅通过 Azure DevOps 个人访问令牌 (PAT) 登录

  4. 配置默认值:建议为组织和项目设置默认配置。 也可以在单独的命令中设置。

     az devops configure --defaults organization=https://dev.azure.com/contoso project=ContosoWebApp
    

命令用法

添加 Azure DevOps 扩展后,将添加 devopspipelinesartifactsboardsrepos 组。 如需了解任何命令的用法和帮助信息,可输入 -h 参数,例如:

az devops -h
Group
    az devops : Manage Azure DevOps organization level operations.
        Related Groups
        az pipelines: Manage Azure Pipelines
        az boards: Manage Azure Boards
        az repos: Manage Azure Repos
        az artifacts: Manage Azure Artifacts.
   
Subgroups:
    admin            : Manage administration operations.
    extension        : Manage extensions.
    project          : Manage team projects.
    security         : Manage security related operations.
    service-endpoint : Manage service endpoints/service connections.
    team             : Manage teams.
    user             : Manage users.
    wiki             : Manage wikis.

Commands:
    configure        : Configure the Azure DevOps CLI or view your configuration.
    feedback         : Displays information on how to provide feedback to the Azure DevOps CLI team.
    invoke           : This command will invoke request for any DevOps area and resource. Please use
                       only json output as the response of this command is not fixed. Helpful docs -
                       https://learn.microsoft.com/rest/api/azure/devops/.
    login            : Set the credential (PAT) to use for a particular organization.
    logout           : Clear the credential for all or a particular organization.

在浏览器中打开项

可以使用 --open 开关在默认浏览器中打开 Azure DevOps 门户中的任何项目。

例如:

az pipelines build show --id 1 --open

此命令在命令行上显示具有 id 1 的生成的详细信息,并在默认浏览器中将其打开。