使用 Azure PipelinesUse Azure Pipelines

Azure Pipelines | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 - TFS 2015Azure Pipelines | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 - TFS 2015

Azure Pipelines 支持持续集成 (CI) 和持续交付 (CD) 来持续、持续地测试和生成代码并将其发送到任何目标。Azure Pipelines supports continuous integration (CI) and continuous delivery (CD) to constantly and consistently test and build your code and ship it to any target. 可以通过定义管道来实现此目的。You accomplish this by defining a pipeline. 使用 YAML 语法或通过用户界面(经典)定义管道。You define pipelines using the YAML syntax or through the user interface (Classic).

Azure Pipelines 支持持续集成 (CI) 和持续交付 (CD) 来持续、持续地测试和生成代码并将其发送到任何目标。Azure Pipelines supports continuous integration (CI) and continuous delivery (CD) to constantly and consistently test and build your code and ship it to any target. 可以通过使用用户界面(也称为 经典)定义管道来实现此目的。You accomplish this by defining a pipeline using the user interface, also referred to as Classic.

备注

在 Microsoft Team Foundation Server (TFS) 2018 和更低版本中,生成和发布管道被称为“定义”,运行被称为“生成”,服务连接被称为“服务终结点”,阶段被称为“环境”,而作业被称为“阶段” 。In Microsoft Team Foundation Server (TFS) 2018 and previous versions, build and release pipelines are called definitions, runs are called builds, service connections are called service endpoints, stages are called environments, and jobs are called phases.

自动执行测试、生成和传递Automate tests, builds, and delivery

持续集成自动执行项目的测试和生成。Continuous integration automates tests and builds for your project. 在开发周期的早期阶段,CI 有助于更快、更快速地修复 bug 或问题。CI helps to catch bugs or issues early in the development cycle, when they're easier and faster to fix. 从 CI 系统生成称为 "项目" 的项。Items known as artifacts are produced from CI systems. 持续交付版本管道使用它们来驱动自动部署。They're used by the continuous delivery release pipelines to drive automatic deployments.

持续交付会自动部署和测试多个阶段中的代码,以帮助提高质量。Continuous delivery automatically deploys and tests code in multiple stages to help drive quality. 持续集成系统生成可部署的项目,包括基础结构和应用。Continuous integration systems produce deployable artifacts, which include infrastructure and apps. 自动发布管道使用这些项目发布新版本,并修复到所选目标。Automated release pipelines consume these artifacts to release new versions and fixes to the target of your choice.

持续集成 (CI)Continuous integration (CI) 持续交付 (CD)Continuous delivery (CD)
-增加代码覆盖率- Increase code coverage
-通过拆分测试和生成运行来更快地生成- Build faster by splitting test and build runs
-自动确保不提供损坏的代码- Automatically ensure you don't ship broken code
-连续运行测试。- Run tests continually.
-自动将代码部署到生产环境- Automatically deploy code to production
-确保部署目标具有最新代码- Ensure deployment targets have latest code
-使用 CI 进程中经过测试的代码。- Use tested code from CI process.

使用 YAML 语法定义管道Define pipelines using YAML syntax

在 YAML 文件中定义管道, azure-pipelines.yml 并将其应用程序的其余部分命名为。You define your pipeline in a YAML file called azure-pipelines.yml with the rest of your app.

管道 YAML 简介图像

  • 通过代码对管道进行版本控制。The pipeline is versioned with your code. 它遵循相同的分支结构。It follows the same branching structure. 可通过拉取请求和分支生成策略中的代码评审来验证更改。You get validation of your changes through code reviews in pull requests and branch build policies.
  • 你使用的每个分支都可以通过修改文件来修改生成策略 azure-pipelines.ymlEvery branch you use can modify the build policy by modifying the azure-pipelines.yml file.
  • 对生成过程所做的更改可能会导致中断,也可能导致意外的结果。A change to the build process might cause a break or result in an unexpected outcome. 由于对代码的其余部分进行的更改是版本控制的,因此可以更轻松地识别问题。Because the change is in version control with the rest of your codebase, you can more easily identify the issue.

按照以下基本步骤操作:Follow these basic steps:

  1. 将 Azure Pipelines 配置为使用 Git 存储库。Configure Azure Pipelines to use your Git repo.
  2. 编辑 azure-pipelines.yml 文件以定义生成。Edit your azure-pipelines.yml file to define your build.
  3. 将代码推送到版本控制存储库。Push your code to your version control repository. 此操作将启动默认触发器,以生成并部署结果,然后监视结果。This action kicks off the default trigger to build and deploy and then monitor the results.

现已更新、构建、测试并打包代码。Your code is now updated, built, tested, and packaged. 可将其部署到任何目标。It can be deployed to any target.

YAML 管道在 TFS 2018 和更早版本中不可用。YAML pipelines aren't available in TFS 2018 and earlier versions.

使用经典接口定义管道Define pipelines using the Classic interface

通过经典用户界面编辑器在 Azure DevOps web 门户中创建和配置管道。Create and configure pipelines in the Azure DevOps web portal with the Classic user interface editor. 定义“生成管道”以生成和测试代码,然后发布项目。You define a build pipeline to build and test your code, and then to publish artifacts. 你还可以定义“发布管道”以使用这些项目并将其部署到部署目标。You also define a release pipeline to consume and deploy those artifacts to deployment targets.

管道设计器简介图像

按照以下基本步骤操作:Follow these basic steps:

  1. 将 Azure Pipelines 配置为使用 Git 存储库。Configure Azure Pipelines to use your Git repo.
  2. 使用 Azure Pipelines 经典编辑器创建和配置生成和发布管道。Use the Azure Pipelines classic editor to create and configure your build and release pipelines.
  3. 将代码推送到版本控制存储库。Push your code to your version control repository. 此操作会触发管道并运行生成或测试代码等任务。This action triggers your pipeline and runs tasks such as building or testing code.

该生成将创建一个项目,该项目由管道的其余部分用于运行任务(例如部署到过渡或生产环境)。The build creates an artifact that's used by the rest of your pipeline to run tasks such as deploying to staging or production.

现已更新、构建、测试并打包代码。Your code is now updated, built, tested, and packaged. 可将其部署到任何目标。It can be deployed to any target.

功能可用性Feature availability

仅当使用 YAML 或使用经典接口定义生成或发布管道时,某些管道功能才可用。Certain pipeline features are only available when using YAML or when defining build or release pipelines with the Classic interface. 下表说明了支持的功能以及哪些任务和方法。The following table indicates which features are supported and for which tasks and methods.

功能Feature YAMLYAML 经典生成Classic Build 经典版本Classic Release 说明Notes
代理Agents Yes Yes Yes 指定运行管道所需的资源。Specifies a required resource on which the pipeline runs.
审批Approvals Yes No Yes 定义一组在完成部署阶段之前需要的验证。Defines a set of validations required prior to completing a deployment stage.
项目Artifacts Yes Yes Yes 支持发布或使用不同的包类型。Supports publishing or consuming different package types.
缓存Caching Yes Yes No 允许在以后的运行中重复使用输出或下载的依赖项来减少生成时间。Reduces build time by allowing outputs or downloaded dependencies from one run to be reused in later runs. 仅在预览版中提供 Azure Pipelines。In Preview, available with Azure Pipelines only.
条件Conditions Yes Yes Yes 指定在运行作业之前要满足的条件。Specifies conditions to be met prior to running a job.
Container jobs(容器作业)Container jobs Yes No No 指定要在容器中运行的作业。Specifies jobs to run in a container.
需求Demands Yes Yes Yes 在运行管道阶段之前确保满足管道要求。Ensures pipeline requirements are met before running a pipeline stage. 需要自承载代理。Requires self-hosted agents.
依赖项Dependencies Yes Yes Yes 指定运行下一个作业或阶段所必须满足的要求。Specifies a requirement that must be met in order to run the next job or stage.
部署组Deployment groups Yes No Yes 定义部署目标计算机的逻辑集。Defines a logical set of deployment target machines.
部署组作业Deployment group jobs No No Yes 指定要发布到部署组的作业。Specifies a job to release to a deployment group.
部署作业Deployment jobs Yes No No 定义部署步骤。Defines the deployment steps.
环境Environment Yes No No 表示作为部署目标的资源的集合。Represents a collection of resources targeted for deployment. 仅适用于 Azure Pipelines。Available with Azure Pipelines only.
GatesGates No No Yes 支持在完成发布阶段之前自动收集和评估外部运行状况信号。Supports automatic collection and evaluation of external health signals prior to completing a release stage. 仅适用于经典发行版。Available with Classic Release only.
作业Jobs Yes Yes Yes 定义一组步骤的执行顺序。Defines the execution sequence of a set of steps.
服务连接Service connections Yes Yes Yes 启用到在作业中执行任务所需的远程服务的连接。Enables a connection to a remote service that is required to execute tasks in a job.
服务容器Service containers Yes No No 使你能够管理容器化服务的生命周期。Enables you to manage the lifecycle of a containerized service.
阶段Stages Yes No Yes 组织管道内的作业。Organizes jobs within a pipeline.
任务组Task groups No Yes Yes 将一系列任务封装到一个可重用的任务中。Encapsulates a sequence of tasks into a single reusable task. 如果使用 YAML,请参阅模板。If using YAML, see templates.
任务Tasks Yes Yes Yes 定义构成管道的构建基块。Defines the building blocks that make up a pipeline.
模板Templates Yes No No 定义可重用的内容、逻辑和参数。Defines reusable content, logic, and parameters.
触发器Triggers Yes Yes Yes 定义导致管道运行的事件。Defines the event that causes a pipeline to run.
变量Variables Yes Yes Yes 表示要传递给管道的数据所替换的值。Represents a value to be replaced by data to pass to the pipeline.
变量组Variable groups Yes Yes Yes 用于存储要控制的值并使其在多个管道中可用。Use to store values that you want to control and make available across multiple pipelines.

TFS 2015 到 TFS 2018 仅支持经典接口。TFS 2015 through TFS 2018 supports the Classic interface only. 下表指示在定义生成管道或发布管道时可用的管道功能。The following table indicates which pipeline features are available when defining build or release pipelines.

功能Feature 经典生成Classic Build 经典版本Classic Release 说明Notes
代理Agents Yes Yes 指定运行管道所需的资源。Specifies a required resource on which the pipeline runs.
审批Approvals No Yes 定义一组在完成部署阶段之前需要的验证。Defines a set of validations required prior to completing a deployment stage.
项目Artifacts Yes Yes 支持发布或使用不同的包类型。Supports publishing or consuming different package types.
条件Conditions Yes Yes 指定在运行作业之前要满足的条件。Specifies conditions to be met prior to running a job.
需求Demands Yes Yes 在运行管道阶段之前确保满足管道要求。Ensures pipeline requirements are met before running a pipeline stage. 需要自承载代理。Requires self-hosted agents.
依赖项Dependencies Yes Yes 指定运行下一个作业或阶段所必须满足的要求。Specifies a requirement that must be met in order to run the next job or stage.
部署组Deployment groups No Yes 定义部署目标计算机的逻辑集。Defines a logical set of deployment target machines.
部署组作业Deployment group jobs No Yes 指定要发布到部署组的作业。Specifies a job to release to a deployment group.
作业Jobs Yes Yes 定义一组步骤的执行顺序。Defines the execution sequence of a set of steps.
服务连接Service connections Yes Yes 启用到在作业中执行任务所需的远程服务的连接。Enables a connection to a remote service that is required to execute tasks in a job.
阶段Stages No Yes 组织管道内的作业。Organizes jobs within a pipeline.
任务组Task groups Yes Yes 将一系列任务封装到一个可重用的任务中。Encapsulates a sequence of tasks into a single reusable task. 如果使用 YAML,请参阅模板。If using YAML, see templates.
任务Tasks Yes Yes 定义构成管道的构建基块。Defines the building blocks that make up a pipeline.
触发器Triggers Yes Yes 定义导致管道运行的事件。Defines the event that causes a pipeline to run.
变量Variables Yes Yes 表示要传递给管道的数据所替换的值。Represents a value to be replaced by data to pass to the pipeline.
变量组Variable groups Yes Yes 用于存储要控制的值并使其在多个管道中可用。Use to store values that you want to control and make available across multiple pipelines.

接下来尝试此操作Try this next