Azure DevOps Services 概览
了解五项 Azure DevOps 服务,创建组织和项目,并连接代码存储库,以开始同时跟踪工作项和提交。
Azure DevOps Services 概览 是 CoddyKit 上的免费 Cloud & IT Cert Prep 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Cloud & IT Cert Prep 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Cloud & IT Cert Prep 课程共包含 4 节课。
什么是 Azure DevOps
Azure DevOps 是 Microsoft 提供的一套云托管开发人员工具,涵盖完整的软件交付生命周期。它将项目管理、源代码管理、构建和发布自动化、测试管理以及项目构件存储整合到一个平台中。使用 Azure DevOps 的团队可以规划冲刺、提交代码、运行自动构建、部署到生产环境并跟踪质量指标,所有操作都可在同一服务中完成,并且能够与其他 Azure 服务深度集成。
Azure DevOps 的五项服务
Azure DevOps 包含五项服务:Azure 看板(Agile 工作项跟踪,包括史诗、故事、任务和 Bug)、Azure Repos(无限 Git 存储库或旧版 TFVC)、Azure Pipelines(适用于任何语言、平台和云的 CI/CD 自动化)、Azure 测试计划(手动测试、探索性测试、测试用例和质量指标)以及Azure Artifacts(适用于 NuGet、npm、Maven、Python 和容器映像的通用包源)。
组织和项目
Azure DevOps 的层次结构从组织开始,这是与您的 Azure AD 租户关联的顶级容器,通常以公司名称命名。在组织中,您可以创建项目,每个项目代表一个软件产品或团队。每个项目都有自己的看板、Repos、Pipelines、测试计划和 Artifacts。访问控制、计费和设置在组织级别配置,但可以针对每个项目进行覆盖。
# Create an Azure DevOps project via CLI
# First install the Azure DevOps extension
az extension add --name azure-devops
# Configure defaults
az devops configure --defaults organization=https://dev.azure.com/myorg
# Create a new project
az devops project create \
--name MyProject \
--description 'E-commerce platform' \
--visibility private \
--process AgileAzure 看板:Agile 规划
Azure 看板支持三种流程模板:Basic(简单的问题和任务)、Agile(史诗、功能、用户故事、任务和 Bug)以及Scrum(史诗、功能、产品待办事项、任务和 Bug)。工作项会在可配置的状态之间流转。看板用于直观显示进行中的工作;冲刺待办事项用于规划容量;待办事项用于确定所有尚未开始工作的优先级。您可以将工作项链接到提交、拉取请求和测试用例,实现完整的可追溯性。
# Create a work item (User Story) via CLI
az boards work-item create \
--title 'Add payment processing' \
--type 'User Story' \
--description 'As a customer I want to pay by credit card' \
--assigned-to developer@contoso.com \
--project MyProject
# List open work items
az boards work-item list \
--project MyProject \
--query "[?fields.\"System.State\"=='Active']"Azure Repos:源代码管理
Azure Repos 提供无限的私有 Git 存储库、分支策略、拉取请求工作流和代码评审工具。分支策略会在受保护分支上强制执行质量门禁:合并前必须满足最低评审人数、构建验证通过、关联工作项以及解决评论等要求。每个存储库都可直接与 Azure Pipelines 集成,在分支推送或拉取请求时自动触发构建和部署。
# Clone an Azure Repos Git repository
git clone https://myorg@dev.azure.com/myorg/MyProject/_git/MyRepo
# Set branch policies via CLI
az repos policy required-reviewer create \
--branch main \
--branch-match-type exact \
--project MyProject \
--repository-id <repo-id> \
--blocking true \
--enabled true \
--minimum-approver-count 2 \
--allow-downvotes falseAzure Pipelines:CI/CD 自动化
Azure Pipelines 是一种 CI/CD 服务,可以构建、测试和部署使用任何语言编写的应用程序,并将其部署到任何平台,包括 Azure、AWS、GCP 和本地环境。Pipelines 定义在与存储库中的代码一同保存的 YAML 文件中。主要概念包括阶段(如 Build、Test、Deploy 等逻辑阶段)、作业(并行执行单元)和步骤(单个任务)。Azure Pipelines 每月为开源项目提供 1,800 分钟的免费构建时间。
# azure-pipelines.yml (minimal CI pipeline)
trigger:
branches:
include:
- main
pool:
vmImage: ubuntu-latest
stages:
- stage: Build
jobs:
- job: BuildJob
steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'
- script: npm install && npm run build
displayName: 'Install and Build'
- script: npm test
displayName: 'Run unit tests'Azure Artifacts:包管理
Azure Artifacts 托管带版本的包源,支持 NuGet(.NET)、npm(Node.js)、Maven(Java)、pip(Python)和通用包(任意二进制文件)。您可以在项目或团队之间共享内部库,而无需将其发布到公共注册表。上游源会通过您的包源代理公共注册表(npmjs.com、nuget.org),让您使用单一终结点管理所有包,并能够审计和缓存依赖项。
# Publish an npm package to Azure Artifacts
npm install -g vsts-npm-auth
vsts-npm-auth -config .npmrc
# .npmrc file:
# registry=https://pkgs.dev.azure.com/myorg/MyProject/_packaging/MyFeed/npm/registry/
# Publish
npm publish --registry https://pkgs.dev.azure.com/myorg/MyProject/_packaging/MyFeed/npm/registry/管道代理:Microsoft 托管与自托管
管道在代理上运行,代理是执行管道作业的虚拟机或容器。Microsoft 托管代理是由 Microsoft 提供的完全托管、预配置虚拟机(Ubuntu、Windows、macOS),无需进行设置。自托管代理运行在您自己的基础设施上(本地环境或 Azure 虚拟机),让您能够控制运行环境、预安装工具以及对私有网络的访问。当构建需要 VNet 访问权限、专用硬件,或需要比云虚拟机更快的启动速度时,请使用自托管代理。
# Register a self-hosted agent on a Linux VM
# 1. Download the agent package
curl -O https://vstsagentpackage.azureedge.net/agent/3.x/vsts-agent-linux-x64-3.x.x.tar.gz
mkdir myagent && tar xzf vsts-agent-linux-x64-3.x.x.tar.gz -C myagent && cd myagent
# 2. Configure the agent
./config.sh --url https://dev.azure.com/myorg --auth pat --token <PAT>
# 3. Run as a service
sudo ./svc.sh install && sudo ./svc.sh start环境与审批
Azure Pipelines 中的 Environments 表示部署目标(开发、Staging、Production),并跟踪部署历史。您可以为环境附加审批和检查门禁——部署到 Production 需要发布经理的人工签字批准。其他检查还包括工作时间门禁(仅允许在 09:00 至 17:00 之间部署)、等待计时器,以及 Azure Monitor 警报检查(存在活动的严重警报时不进行部署)。这样,团队就能对高风险的生产部署实施治理。
# YAML: deployment job targeting an environment with approval
- stage: DeployProd
jobs:
- deployment: DeployToProduction
environment:
name: Production # Requires manual approval in Azure DevOps portal
resourceType: VirtualMachine
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp@1
inputs:
appName: myapp-prod
package: '$(Pipeline.Workspace)/drop/app.zip'服务连接
服务连接用于存储与外部服务(Azure 订阅、GitHub、Docker Hub、SonarQube、Kubernetes 集群)的已认证连接,使 Pipelines 无需将凭据嵌入 YAML 即可使用这些服务。Azure Resource Manager 服务连接使用服务主体或托管标识来部署 Azure 资源。所有凭据都会加密,并限定在项目或 Pipeline 范围内,从而防止凭据暴露在 Pipeline 日志中。
# Create an Azure Resource Manager service connection via CLI
az devops service-endpoint azurerm create \
--azure-rm-service-principal-id '<AppId>' \
--azure-rm-subscription-id '<SubId>' \
--azure-rm-subscription-name 'MySubscription' \
--azure-rm-tenant-id '<TenantId>' \
--name 'AzureProductionSC' \
--project MyProject
# Use in pipeline YAML
# - task: AzureCLI@2
# inputs:
# azureSubscription: 'AzureProductionSC'
# scriptType: bash
# scriptLocation: inlineScriptAzure DevOps 与 GitHub 的比较
Microsoft 同时拥有 Azure DevOps 和 GitHub,二者都支持 CI/CD。对于深度使用 Microsoft 工具、需要 Azure Boards、Test Plans 或 Artifacts 的企业,通常更适合使用 Azure DevOps。对于开源项目、以开发者为中心的工作流,以及团队已经使用 GitHub 仓库的情况,通常更适合使用 GitHub。GitHub Actions 是 GitHub 的 CI/CD 平台。Azure Pipelines 可与 Azure Repos 和 GitHub 集成,因此您可以将 Azure Boards 和 Artifacts 与 GitHub 仓库结合使用。
快速检查
请测试您对本课 Microsoft Azure Fundamentals (AZ-900) 概念的理解。
课程回顾
本课您学习了:Azure DevOps 提供五项集成服务,涵盖规划(Boards)、源代码管理(Repos)、CI/CD(Pipelines)、测试(Test Plans)和包管理(Artifacts);带审批的环境可以为高风险部署设置门禁;服务连接可以安全地存储外部服务凭据,供 Pipeline 使用。接下来,我们将学习如何使用 Azure Pipelines 构建 CI Pipeline。
常见问题解答
「Azure DevOps Services 概览」课时是免费的吗?
是的 — 「Azure DevOps Services 概览」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Cloud & IT Cert Prep 课程的其余内容,请升级到 CoddyKit PRO。 Cloud & IT Cert Prep 课程共包含 4 节课。
「Azure DevOps Services 概览」这节课中我会学到什么?
了解五项 Azure DevOps 服务,创建组织和项目,并连接代码存储库,以开始同时跟踪工作项和提交。 你通过在浏览器中直接运行的动手代码来练习 Cloud & IT Cert Prep,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Cloud & IT Cert Prep 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Cloud & IT Cert Prep 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。
「Azure DevOps Services 概览」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Cloud & IT Cert Prep 课中编写并运行代码吗?
能。每节 Cloud & IT Cert Prep 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- Azure DevOps Services 概览
- 使用 Azure Pipelines 构建 CI 管道
- 持续部署到 Azure
- Azure 上的 GitHub Actions