jobs.<job_id>.services.<service_id> 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.<service_id>
to uniquely identify a service.
Example usage
To allow the steps within a job to access the service instances, use localhost or 127.0.0.1 as the host and the corresponding port for the service. |
apiVersion: automation.cloudbees.io/v1alpha1 kind: workflow name: MySQL service example on: push: jobs: test: (1) services: my-service: (2) image: mysql:8.0 env: MYSQL_ROOT_PASSWORD: examplepassword MYSQL_DATABASE: exampledb args: "--default-authentication-plugin=mysql_native_password" steps: - name: Wait for MySQL service (3) uses: docker://mysql:8.0 run: | until mysqladmin ping -h 127.0.0.1 --silent; do echo "Waiting for database connection..." sleep 2 done env: MYSQL_PWD: examplepassword - name: Run a query (4) uses: docker://mysql:8.0 run: | echo "SHOW DATABASES;" | mysql -u root -h 127.0.0.1 env: MYSQL_PWD: examplepassword
1 | The job ID test defines a job that runs when code is pushed to the repository. |
2 | The my-service service ID uniquely identifies a MySQL service container used in the test job. |
3 | This step waits for the MySQL service to be ready by repeatedly pinging it until it responds. |
4 | This step sends a SQL query to the my-service to list all available databases. |