jobs.job.container definition

容器作业允许在容器而不是代理主机上运行作业。

引用此定义的定义:管道jobs.jobjobs.deployment

实现

执行 说明
容器:字符串 按别名指定作业容器。
容器:映像 使用映像标记和选项指定作业容器。

container: string

按别名指定作业容器。

container: string # Specify job container by alias.

container 字符串。

按别名指定作业容器。

注解

别名可以是映像的名称,也可以是对 容器资源的引用。

例子

以下示例从 Docker 中心提取标记为 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 字符串。
连接到专用容器注册表的服务终结点 ID。

env 字符串字典。
变量映射到容器的环境。

mapDockerSocket 布尔
将此标志设置为 false 以强制代理不要在容器作业上设置 /var/run/docker.sock 卷。

options 字符串。
要传入容器主机的选项。

ports 字符串列表。
要公开在容器上的端口。

volumes 字符串列表。
要装载到容器上的卷。

mountReadOnly mountReadOnly
卷装载只读,默认值为 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 字符串。
连接到专用容器注册表的服务终结点 ID。

env 字符串字典。
变量映射到容器的环境。

mapDockerSocket 布尔
将此标志设置为 false 以强制代理不要在容器作业上设置 /var/run/docker.sock 卷。

options 字符串。
要传入容器主机的选项。

ports 字符串列表。
要公开在容器上的端口。

volumes 字符串列表。
要装载到容器上的卷。

例子

使用 options 配置容器启动。

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

steps:
- script: echo hello

在以下示例中,容器在资源部分中定义。 然后,通过引用其分配的别名来引用每个容器。

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

另请参阅