jobs.job.container 定義

コンテナー ジョブを使用すると、エージェント ホストではなくコンテナーでジョブを実行できます。

この定義を参照する定義: pipelinejobs.jobjobs.deployment

この定義を参照する定義: pipelinejobs.job

実装

実装 説明
container: string 別名でジョブ コンテナーを指定します。
container: image イメージ タグとオプションを使用してジョブ コンテナーを指定します。

container: string

別名でジョブ コンテナーを指定します。

container: string # Specify job container by alias.

container 文字列。

別名でジョブ コンテナーを指定します。

解説

別名には、イメージの名前を指定することも、 コンテナー リソースへの参照にすることもできます。

次の例では、18.04 というタグが付いた ubuntu イメージをDocker Hubからフェッチし、コンテナーを起動します。 コマンドを printenv 実行すると、ubuntu:18.04 コンテナー内で実行されます。

pool:
  vmImage: 'ubuntu-18.04'

container: ubuntu:18.04

steps:
- script: printenv

container: image

イメージ タグとオプションを使用してジョブ コンテナーを指定します。

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 文字列ディクショナリ。
コンテナーの環境にマップする変数。

mapDockerSocketboolean
コンテナー ジョブで /var/run/docker.sock ボリュームを設定しないようにエージェントを強制するには、このフラグを false に設定します。

options 文字列。
コンテナー ホストに渡すオプション。

ports 文字列リスト。
コンテナーで公開するポート。

volumes 文字列リスト。
コンテナーにマウントするボリューム。

mountReadOnlymountReadOnly
読み取り専用でマウントするボリューム。既定値はすべて false です。

container: image

イメージ タグとオプションを使用してジョブ コンテナーを指定します。

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 文字列ディクショナリ。
コンテナーの環境にマップする変数。

mapDockerSocketboolean
コンテナー ジョブで /var/run/docker.sock ボリュームを設定しないようにエージェントを強制するには、このフラグを false に設定します。

options 文字列。
コンテナー ホストに渡すオプション。

ports 文字列リスト。
コンテナーで公開するポート。

volumes 文字列リスト。
コンテナーにマウントするボリューム。

container: image

イメージ タグとオプションを使用してジョブ コンテナーを指定します。

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 文字列。
プライベート コンテナー レジストリに接続するサービス エンドポイントの ID。

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

関連項目