jobs.deployment.strategy.runOnce 定義

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

屬性

preDeploypreDeployHook
針對 runOnce 部署策略預先部署攔截。

deploydeployHook
部署 runOnce 部署策略的攔截。

routeTrafficrouteTrafficHook
路由傳送 runOnce 部署策略的流量攔截。

postRouteTrafficpostRouteTrafficHook
發佈 RunOnce 部署策略的路由流量攔截。

ononSuccessOrFailureHook
在 runOnce 部署策略的成功或失敗勾點時。

備註

runOnce是最簡單的部署策略,其中所有生命週期勾點, preDeploydeploy 也就是 、 routeTrafficpostRouteTraffic 都會執行一次。 然後會執行 on:successon:failure

生命週期勾點的描述

preDeploy:用來執行在應用程式部署開始之前初始化資源的步驟。

deploy:用來執行部署應用程式的步驟。 下載成品工作只會在部署作業的勾點中 deploy 自動插入。 若要停止下載成品,請使用 - download: none 或選擇要下載的特定成品,方法是指定 [下載管線成品] 工作

routeTraffic:用來執行提供已更新版本流量的步驟。

postRouteTraffic:用來在路由傳送流量之後執行步驟。 一般而言,這些工作會監視已更新版本的健全狀況,以取得定義的間隔。

on: failureon: 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) ,因為部署作業已連結至環境。 這在針對作業的多個步驟設定相同的連線詳細資料的情況下很有用。

另請參閱