jobs.deployment.strategy.rolling definition

进行滚动部署时,每次迭代都会将旧版应用程序的实例替换为固定的虚拟机集(滚动集)中新版应用程序的实例。

rolling:
  maxParallel: string # Maximum number of jobs running in parallel.
  preDeploy: # Pre deploy hook for rolling deployment strategy.
    steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ] # A list of steps to run.
    pool: string | pool # Pool where pre deploy steps will run.
  deploy: # Deploy hook for rolling deployment strategy.
    steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ] # A list of steps to run.
    pool: string | pool # Pool where deploy steps will run.
  routeTraffic: # Route traffic hook for rolling deployment strategy.
    steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ] # A list of steps to run.
    pool: string | pool # Pool where route traffic steps will run.
  postRouteTraffic: # Post route traffic hook for rolling deployment strategy.
    steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ] # A list of steps to run.
    pool: string | pool # Pool where post route traffic steps will run.
  on: # On success or failure hook for rolling deployment strategy.
    failure: # Runs on failure of any step.
      steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ] # A list of steps to run.
      pool: string | pool # Pool where post on failure steps will run.
    success: # Runs on success of all of the steps.
      steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ] # A list of steps to run.
      pool: string | pool # Pool where on success steps will run.

引用此定义的定义: jobs.deployment.strategy

属性

maxParallel 字符串。
并行运行的最大作业数。

preDeploypreDeployHook
预部署挂钩,用于滚动部署策略。

deploydeployHook
为滚动部署策略部署挂钩。

routeTrafficrouteTrafficHook
用于滚动部署策略的路由流量挂钩。

postRouteTrafficpostRouteTrafficHook
发布用于滚动部署策略的路由流量挂钩。

ononSuccessOrFailureHook
滚动部署策略的成功或失败挂钩。

备注

Azure Pipelines 目前仅支持对 VM 资源的滚动策略。

例如,滚动部署通常等待每组虚拟机上的部署完成,然后继续下一组部署。 可以在每次迭代后执行运行状况检查,如果出现重大问题,可以停止滚动部署。

可以通过在 strategy: 节点下指定关键字 rolling: 来配置滚动部署。 strategy.name 变量在此策略块中可用,该策略块采用策略的名称。 在本例中为 rolling。

支持所有生命周期挂钩,并创建生命周期挂钩作业以在每个 VM 上运行。

preDeploydeployrouteTrafficpostRouteTraffic 根据 maxParallel 定义的批大小执行一次。 然后,执行 on: successon: failure

使用 maxParallel: <# or % of VMs>,可以控制要并行部署到的虚拟机目标的数量/百分比。 这可确保应用在这些计算机上运行,并且能够在其余计算机上进行部署时处理请求,从而减少总体停机时间。

注意

此功能存在一些已知的差距。 例如,重试某个阶段时,它将在所有 VM 上重新运行部署,而不仅仅是在失败的目标上。

生命周期挂钩的说明

preDeploy:用于在应用程序部署开始之前运行初始化资源的步骤。

deploy:用于运行部署应用程序的步骤。 下载工件任务将仅在部署作业的 deploy 挂钩中自动注入。 要停止下载工件,请使用 - download: none,或通过指定下载管道工件任务来选择要下载的特定工件。

routeTraffic:用于运行向更新版本发送流量的步骤。

postRouteTraffic:用于在路由流量后运行步骤。 通常,这些任务按定义的时间间隔监视更新版本的运行状况。

on: failureon: success:用于运行回滚操作或清理的步骤。

示例

以下 VM 滚动策略示例在每次迭代中最多更新五个目标。 maxParallel 将确定可以并行部署的目标数。 选择包括在任何时候必须保持可用的目标的绝对数量或百分比,不包括正在部署的目标。 它还用于确定部署过程中的成功和失败条件。

jobs: 
- deployment: VMDeploy
  displayName: web
  environment:
    name: smarthotel-dev
    resourceType: VirtualMachine
  strategy:
    rolling:
      maxParallel: 5  #for percentages, mention as x%
      preDeploy:
        steps:
        - download: current
          artifact: drop
        - script: echo initialize, cleanup, backup, install certs
      deploy:
        steps:
        - task: IISWebAppDeploymentOnMachineGroup@0
          displayName: 'Deploy application to Website'
          inputs:
            WebSiteName: 'Default Web Site'
            Package: '$(Pipeline.Workspace)/drop/**/*.zip'
      routeTraffic:
        steps:
        - script: echo routing traffic
      postRouteTraffic:
        steps:
        - script: echo health check post-route traffic
      on:
        failure:
          steps:
          - script: echo Restore from backup! This is on failure
        success:
          steps:
          - script: echo Notify! This is on success

请参阅