通过部署策略,可以配置更新的交付方式。
引用此定义的定义:jobs.deployment
实现
执行 | 说明 |
---|---|
策略:runOnce | 运行一次部署策略。 |
策略:滚动 | 滚动部署策略。 |
策略:canary | Canary 部署策略。 |
注解
部署应用程序更新时,用于交付更新的技术必须:
- 启用初始化。
- 部署更新。
- 将流量路由到更新的版本。
- 在路由流量后测试更新的版本。
- 如果失败,请运行步骤以还原到最后一个已知良好版本。
我们通过使用可以在部署过程中运行步骤的生命周期挂钩来实现此目的。 每个生命周期挂钩都解析为代理作业或服务器作业(或将来的容器或验证作业),具体取决于池属性。 默认情况下,生命周期挂钩将继承部署作业指定的池。
部署作业使用 $(Pipeline.Workspace) system variable.
如果使用自承载代理,则可以使用工作区清理选项来清理部署工作区。
jobs:
- deployment: deploy
pool:
vmImage: ubuntu-latest
workspace:
clean: all
environment: staging
策略:runOnce
runOnce 部署策略通过一次执行其每个步骤来推出更改。
strategy:
runOnce: # RunOnce Deployment strategy.
preDeploy: # Pre deploy hook for runOnce 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 runOnce 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 runOnce 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 runOnce 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 runOnce 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.
性能
runOnce
jobs.deployment.strategy.runOnce。
RunOnce 部署策略。
注解
runOnce
是最简单的部署策略,其中所有生命周期挂钩(即 preDeploy
deploy
、routeTraffic
和 postRouteTraffic
)执行一次。 然后,执行 on: success
或 on: failure
。
策略:滚动
滚动部署将应用程序的早期版本的实例替换为每个迭代中固定虚拟机(滚动集)上应用程序的新版本实例。
strategy:
rolling: # Rolling Deployment strategy.
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.
性能
rolling
jobs.deployment.strategy.rolling。
滚动部署策略。
策略:Canary
Canary 部署策略对一小部分服务器进行了更改。
strategy:
canary: # Canary Deployment strategy.
increments: [ string ] # Maximum batch size for deployment.
preDeploy: # Pre deploy hook for canary 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 canary 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 canary 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 canary 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 canary 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.
性能
canary
jobs.deployment.strategy.canary。
Canary 部署策略。
注解
Canary 部署策略是一种高级部署策略,可帮助降低推出新版本应用程序时所涉及的风险。 使用此策略,可以首先对一小部分服务器进行更改。 当你对新版本更有信心时,可以将其发布到基础结构中的更多服务器,并向其路由更多流量。