Launch price: every exam for $29.99 a year, for the first 300 buyers. See the price

CertStreak
Menu

Develop and implement complex pipeline scenarios, such as hybrid pipelines, VM templates, and self-hosted runners or agents

A worked example

Single answer

You are adding integration tests to a YAML pipeline that runs on a Microsoft-hosted Ubuntu agent. The tests need a Redis instance, so you add a service container, as shown in the exhibit. The job has no container property and runs directly on the agent host.

resources:
  containers:
  - container: cache
    image: redis
    ports:
    - 6379:6379

pool:
  vmImage: 'ubuntu-latest'

services:
  redis: cache

steps:
- script: ./run-integration-tests.sh --redis-host <HOST> --redis-port 6379

Which value should replace <HOST> so that the tests can reach Redis?

Choose one answer
Why

The job runs on the agent host, not in a container. In that case Azure Pipelines provides no automatic name resolution for service containers, and the job reaches them through localhost. Jobs on the host also need ports to reach the service container, and the 6379:6379 mapping exposes Redis on host port 6379. Service names such as redis resolve only from inside a job container on the shared Docker network.

  • Not correct: redis. Reaching a service by its services name depends on Docker networking between the job container and the service containers. A job that runs on the host gets no automatic name resolution.
  • Correct: localhost. In a noncontainer job, service containers are reached through localhost on the mapped host port. Here port 6379 on the host maps to the Redis container.
  • Not correct: cache. cache is the container resource name. A job that runs directly on the host gets no automatic name resolution for service containers, so this name does not resolve.
  • Not correct: redis.cache. A job that runs directly on the host has no automatic name resolution for service containers, so no combined service or resource host name is provided.

Practise this topic until it's automatic.

Ten questions a day, every answer explained, and misses that come back until you beat them.

Start free