Background
Run dependent services for the duration of a stage
Background steps run dependent services for the duration of a stage.
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 pingIt 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:
Add a health check (preferred)
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?