jobs.<job_id>.services is a Preview feature.
|
A Preview feature:
Product features and documentation are frequently updated. If you find an issue or have a suggestion, please contact CloudBees Support. |
Use jobs.<job_id>.services
to run a service in a separate container alongside the job for the duration of the run, providing functionality such as a database or application server.
Example usage
This example starts a PostgreSQL service, sets credentials with environment variables, and verifies connectivity with a simple SQL query.
apiVersion: automation.cloudbees.io/v1alpha1 kind: workflow name: Postgres service example on: push jobs: test: services: (1) postgres: (2) image: postgres:17-alpine3.20 (3) env: (4) POSTGRES_USER: testuser (5) POSTGRES_PASSWORD: testpassword POSTGRES_DB: testdb steps: - name: Run tests against postgres db uses: docker://postgres:17 env: DATABASE_URL: postgres://testuser:testpassword@localhost:5432/testdb (6) run: | psql -h localhost -U testuser -d testdb -c "SELECT 'Hello, PostgreSQL!' AS greeting;"
1 | Declares service containers that run alongside the job. |
2 | Names the PostgreSQL service. |
3 | Pins the service image version. |
4 | Provides environment variables consumed by the postgres image at startup. |
5 | Sets default user, password, and database created by the service. |
6 | Connects to the service on localhost:5432 using the configured credentials. |