runOnce 部署策略會執行每個步驟一次來推出變更。
runOnce:
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.
參考此定義的定義:jobs.deployment.strategy
性能
preDeploy
preDeployHook。
RunOnce 部署策略的預先部署攔截。
deploy
deployHook。
runOnce 部署策略的部署攔截。
routeTraffic
routeTrafficHook。
RunOnce 部署策略的路由流量攔截。
postRouteTraffic
postRouteTrafficHook。
RunOnce 部署策略的 Post 路由流量攔截。
on
onSuccessOrFailureHook。
runOnce 部署策略的成功或失敗勾點。
備註
runOnce 是最簡單的部署策略,即 preDeploydeploy、routeTraffic和 postRouteTraffic等所有生命周期攔截都會執行一次。 然後,會執行 on:success 或 on:failure。
生命週期勾點的描述
preDeploy:用來執行在應用程式部署開始前初始化資源的步驟。
deploy:用來執行部署應用程式的步驟。 下載成品工作只會在部署作業的 deploy 攔截中自動插入。 若要停止下載成品,請使用 - download: none,或指定 下載管線成品工作來下載特定成品。
routeTraffic:用來執行提供流量至更新版本的步驟。
postRouteTraffic:用來在路由傳送流量之後執行步驟。 一般而言,這些工作會監視已定義間隔更新版本的健康情況。
on: failure 或 on: success:用來執行復原動作或清除的步驟。
範例
下列範例 YAML 代碼段會使用 runOnce 部署策略來展示部署作業的簡單用法。 此範例包含結帳步驟。
jobs:
# Track deployments on the environment.
- deployment: DeployWeb
displayName: deploy Web App
pool:
vmImage: ubuntu-latest
# Creates an environment if it doesn't exist.
environment: 'smarthotel-dev'
strategy:
runOnce:
deploy:
steps:
- checkout: self
- script: echo my first deployment
每次執行此作業時,都會針對 smarthotel-dev 環境記錄部署歷程記錄。
備註
- 您也可以建立具有空白資源的環境,並使用該環境做為抽象殼層來記錄部署歷程記錄,如上一個範例所示。
下一個範例示範管線如何同時參考環境和資源,做為部署作業的目標。
jobs:
- deployment: DeployWeb
displayName: deploy Web App
pool:
vmImage: ubuntu-latest
# Records deployment against bookings resource - Kubernetes namespace.
environment: 'smarthotel-dev.bookings'
strategy:
runOnce:
deploy:
steps:
# No need to explicitly pass the connection details.
- task: KubernetesManifest@0
displayName: Deploy to Kubernetes cluster
inputs:
action: deploy
namespace: $(k8sNamespace)
manifests: |
$(System.ArtifactsDirectory)/manifests/*
imagePullSecrets: |
$(imagePullSecret)
containers: |
$(containerRegistry)/$(imageRepository):$(tag)
此方法有下列優點:
- 記錄環境中特定資源的部署歷程記錄,而不是記錄環境中所有資源的歷程記錄。
- 部署作業中的步驟 會自動繼承 資源的連接詳細數據(在此案例中為 Kubernetes 命名空間,
smarthotel-dev.bookings),因為部署作業已連結至環境。 在針對作業的多個步驟設定相同的連線詳細數據的情況下,這非常有用。