jobs.job.container definition

容器作業可讓您在容器上執行作業,而不是代理程式主機。

參考此定義的定義: pipelinejobs.jobjobs.deployment

參考此定義的定義: pipelinejobs.job

實作

實作 描述
container: string 依別名指定作業容器。
容器:映射 使用映射標記和選項指定作業容器。

container: string

依別名指定作業容器。

container: string # Specify job container by alias.

container 字串。

依別名指定作業容器。

備註

別名可以是映射的名稱,也可以是 容器資源的參考。

範例

下列範例會從Docker Hub擷取標記為 18.04 的 ubuntu 映射,然後啟動容器。 當 printenv 命令執行時,它會在 ubuntu:18.04 容器內發生。

pool:
  vmImage: 'ubuntu-18.04'

container: ubuntu:18.04

steps:
- script: printenv

容器:映射

使用映射標記和選項指定作業容器。

container:
  image: string # Required. Container image tag.
  endpoint: string # ID of the service endpoint connecting to a private container registry.
  env: # Variables to map into the container's environment.
    string: string # Name/value pairs
  mapDockerSocket: boolean # Set this flag to false to force the agent not to setup the /var/run/docker.sock volume on container jobs.
  options: string # Options to pass into container host.
  ports: [ string ] # Ports to expose on the container.
  volumes: [ string ] # Volumes to mount on the container.
  mountReadOnly: # Volumes to mount read-only, the default is all false.
    work: boolean # Mount the work directory as readonly.
    externals: boolean # Mount the externals directory as readonly.
    tools: boolean # Mount the tools directory as readonly.
    tasks: boolean # Mount the tasks directory as readonly.

屬性

image 字串。 必要。
容器映射標籤。

endpoint 字串。
連線到私人容器登錄的服務端點識別碼。

env 字串字典。
要對應至容器環境的變數。

mapDockerSocket布林值
將此旗標設定為 false,強制代理程式不要在容器作業上設定 /var/run/docker.sock 磁片區。

options 字串。
傳遞至容器主機的選項。

ports 字串清單。
要公開在容器上的埠。

volumes 字串清單。
要掛接在容器上的磁片區。

mountReadOnlymountReadOnly
要掛接唯讀的磁片區,預設值全部為 false。

容器:映射

使用映射標記和選項指定作業容器。

container:
  image: string # Required. Container image tag.
  endpoint: string # ID of the service endpoint connecting to a private container registry.
  env: # Variables to map into the container's environment.
    string: string # Name/value pairs
  mapDockerSocket: boolean # Set this flag to false to force the agent not to setup the /var/run/docker.sock volume on container jobs.
  options: string # Options to pass into container host.
  ports: [ string ] # Ports to expose on the container.
  volumes: [ string ] # Volumes to mount on the container.

屬性

image 字串。 必要。
容器映射標籤。

endpoint 字串。
連線到私人容器登錄的服務端點識別碼。

env 字串字典。
要對應至容器環境的變數。

mapDockerSocket布林值
將此旗標設定為 false,強制代理程式不要在容器作業上設定 /var/run/docker.sock 磁片區。

options 字串。
傳遞至容器主機的選項。

ports 字串清單。
要公開在容器上的埠。

volumes 字串清單。
要掛接在容器上的磁片區。

容器:映射

使用映射標記和選項指定作業容器。

container:
  image: string # Required. Container image tag.
  endpoint: string # ID of the service endpoint connecting to a private container registry.
  env: # Variables to map into the container's environment.
    string: string # Name/value pairs
  options: string # Options to pass into container host.
  ports: [ string ] # Ports to expose on the container.
  volumes: [ string ] # Volumes to mount on the container.

屬性

image 字串。 必要。
容器映射標籤。

endpoint 字串。
連線到私人容器登錄的服務端點識別碼。

env 字串字典。
要對應至容器環境的變數。

options 字串。
傳遞至容器主機的選項。

ports 字串清單。
要公開在容器上的埠。

volumes 字串清單。
要掛接在容器上的磁片區。

範例

使用 options 來設定容器啟動。

container:
  image: ubuntu:18.04
  options: --hostname container-test --ip 192.168.0.1

steps:
- script: echo hello

在下列範例中,容器定義于 resources 區段中。 之後會參考每個容器,方法是參考其指派的別名。

resources:
  containers:
  - container: u14
    image: ubuntu:14.04

  - container: u16
    image: ubuntu:16.04

  - container: u18
    image: ubuntu:18.04

jobs:
- job: RunInContainer
  pool:
    vmImage: 'ubuntu-18.04'

  strategy:
    matrix:
      ubuntu14:
        containerResource: u14
      ubuntu16:
        containerResource: u16
      ubuntu18:
        containerResource: u18

  container: $[ variables['containerResource'] ]

  steps:
  - script: printenv

另請參閱