Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Running Laravel tests with database in pipeline

Artis Smirnovs
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Oct 25, 2023

I have an issue running tests that requires DB connection. First part where pipeline is built works fine. Even `php artisan migrate` goes through.
But Test step fails when test tries to add data to database with: `could not find driver (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')` . I tried changing host to 127.0.0.1 or mysql but it doesn't change anything.
 
Most of my .yml file is based on example I found in bitbucket documentation so I am nt sure why its not working.

Here is my bitbucket-pipelines.yml file:

# Template PHP Build

# This template allows you to validate your PHP application.
# The workflow allows running tests and code linting on the default branch.
image: php:8.2-fpm

pipelines:
default:
- step:
script:
- apt-get update && apt-get install -y unzip zip
- apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
- apt-get update && apt-get install -qy git curl libmcrypt-dev default-mysql-client
- docker-php-ext-install pdo pdo_mysql
- yes | pecl install mcrypt-1.0.6
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- COMPOSER_ALLOW_SUPERUSER=1 composer install
- cp .env.pipeline .env
- php artisan migrate --force
artifacts:
- storage/**
- vendor/**
- public/**
- .env
caches:
- composer
services:
- mysql
- parallel:
- step:
name: Tests
script:
- php artisan test
definitions:
services:
mysql:
image: mysql:5.7
environment:
MYSQL_DATABASE: 'homestead'
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_USER: 'homestead'
MYSQL_PASSWORD: 'secret'

And here is .env:

APP_ENV=local
APP_KEY=ThisIsThe32CharacterKeySecureKey
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

 

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Oct 27, 2023

Hi Artis and welcome to the community!

At the moment there is no mechanism for a Pipelines build to wait for service startup (we have a request in our issue tracker for the build to wait until all services are ready: https://jira.atlassian.com/browse/BCLOUD-15244). If the command that fails is the first one in that step, the mysql service may not be ready yet. You can try adding a wait command as the first command of the build (e.g. for 5, 10 or 30 seconds) and see if that helps.

Please also ensure that:

  • you have added the service in the step definition
  • you are using as host name 127.0.0.1 (avoid using localhost, as some clients will attempt to connect via a local "Unix socket", which will not work in Pipelines)

You can also try debugging the build locally with Docker (using the same images you have in your yml file) to ensure that the configuration in your code is correct and the build succeeds locally with Docker:

In step 3 of the guide, there is a section on how to test with build services.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events