共用方式為


目標定義

工作會在執行內容中執行,也就是代理程式主機或容器。

參考此定義的定義:steps.tasksteps.scriptsteps.powershellsteps.pwshsteps.bashsteps.checkoutsteps.downloadsteps.downloadBuildsteps.getPackagesteps.publishsteps.reviewApp

實作

實施 說明
目標:字串 執行此步驟或工作的環境。
目標:容器、命令、settableVariables 使用環境設定步驟目標,以及允許的命令和變數清單。
實施 說明
目標:字串 執行此步驟或工作的環境。
目標:容器、命令 使用環境和允許的命令清單來設定步驟目標。

備註

個別步驟可以藉由指定 target來覆寫其內容,並選擇性地設定容器、命令和可設定變數。

target:string

依名稱指定步驟目標。

target: string # Environment in which to run this step or task.

target 字串。

可用的選項是將代理程式主機加上管線中定義之任何容器的字 host 組。

目標:容器、命令、settableVariables

使用容器名稱、命令和可設定變數來設定步驟目標。

target:
  container: string # Container to target (or 'host' for host machine).
  commands: any | restricted # Set of allowed logging commands ('any' or 'restricted').
  settableVariables: none | [ string ] # Restrictions on which variables that can be set.

性能

container 字串。
要以主機計算機為目標的容器(或 「主機」)。

commands 字串。
一組允許的記錄命令 ('any' 或 'restricted')。 any |限制。

settableVariables target.settableVariables
可設定變數的限制。

目標:容器、命令

使用環境和允許的命令清單來設定步驟目標。

target:
  container: string # Container to target (or 'host' for host machine).
  commands: any | restricted # Set of allowed logging commands ('any' or 'restricted').

性能

container 字串。
要以主機計算機為目標的容器(或 「主機」)。

commands 字串。
一組允許的記錄命令 ('any' 或 'restricted')。 any |限制。

備註

設定步驟目標時,您不需要設定所有這些屬性。 如果未指定,container 的預設值會 hostcommands 的預設值 any,而 settableVariables 的預設值可讓步驟設定所有變數。

步驟定位與指令隔離

Azure Pipelines 支援在容器或代理程式主機上執行作業。 先前,整個作業已設定為這兩個目標的其中一個。 現在,個別步驟(工作或腳本)可以在您選擇的目標上執行。 步驟也可能以其他容器為目標,因此管線可以在專用的容器中執行每個步驟。

備註

這項功能處於公開預覽狀態。 如果您有此功能的任何意見反應或問題,請在 開發人員社群中告訴我們。

容器可以做為隔離界限,防止程式代碼在主計算機上進行非預期的變更。 與代理程式 通訊和存取服務的方式,不會受到容器中隔離步驟的影響。 因此,我們也引進了命令限制模式,您可以搭配步驟目標使用。 將 commands 設定為 restricted 會限制步驟可從代理程式要求的服務。 它將無法附加日誌、上傳工件,以及執行某些其他操作。

範例

下列範例示範在作業容器和另一個容器的主機上執行步驟。

resources:
  containers:
  - container: python
    image: python:3.8
  - container: node
    image: node:13.2

jobs:
- job: example
  container: python

  steps:
  - script: echo Running in the job container

  - script: echo Running on the host
    target: host

  - script: echo Running in another container, in restricted commands mode
    target:
      container: node
      commands: restricted

另請參閱