For the complete documentation index, see llms.txt. This page is also available as Markdown.

Background

Run dependent services for the duration of a stage

Background steps run dependent services for the duration of a stage.

Background step exit codes are ignored. A non-zero exit code does not fail the overall pipeline.

Background containers tend to exit with a non-zero exit code, since they often need to be killed after the pipeline completes.

Communication

Background containers are reachable at a hostname identical to the container name.

This pipeline has a ping step that communicates with a Redis background step named cache.

kind: pipeline
spec:
  stages:
  - type: ci
    spec:
      steps:
      - name: cache
        type: background
        spec:
          container: redis

      - name: ping
        type: run
        spec:
          container: redis
          script: |-
            redis-cli -h cache ping

It is important to remember that after a container is started, the software running inside the container (e.g. redis) takes time to initialize and begin accepting connections.

There are two approaches to this problem:

  1. Add a health check (preferred)

  2. Add a sleep

Health check

Use a commandline tool to check if a service is up and running.

This pipeline runs MySQL as a background step, with a run step that uses the mysqladmin tool to check if the MySQL server is available. Once the database is ready, the database creation command runs.

Sleep

Give the background step adequate time to initialize before attempting to connect.

A simple solution is to use the sleep command.

Last updated

Was this helpful?